form = document.formname;
if(! /^\w+$/.test(form.userid.value))
  alert("userid 非法");
if(! /^\w+$/.test(form.password.value))
  alert("password 非法");

解决方案 »

  1.   

    xuzuning(唠叨):
    能解释一下吗?都说的是什么意思?我没有理解
      

  2.   

    我的登陆表单代码如下,如何在按下提交按钮后,先判断两个表单变量$userid和$password中是否含有非法字符,如果没有才提交给cl.php进行处理? 我初学PHP,麻烦各位说详细一点,拜托各位了!!!<?php
    echo "<table width=200 valign=top>";echo "<tr><td width=100% valign=top>";
    echo "<form name=form1 method=post action=cl.php>";echo "<table width=100% valign=top cellspacing=2>";
    echo "<tr><td height=20 background=img/dh1.gif align=center><span class=bz>...:::</span>&nbsp;&nbsp;用户登陆&nbsp;&nbsp;<span class=bz>:::...</span></td></tr>";
    echo "<tr><td bgcolor=#8BA677>";echo "<table width=100% valign=top>";echo "<br><tr><td width=40% height=30 align=center>用户名:</td>";
    echo "<td width=60% height=30 align=left><input name=userid type=text size=10></td></tr>";echo "<tr><td width=40% height=30 align=center>口&nbsp;&nbsp;令:</td>";
    echo "<td width=60% height=30 align=left><input name=password type=text size=10></td></tr>";echo "<table width=100%><tr><td height=50 align=center>";
    echo"<input type=submit name=submdl value=登陆>&nbsp;";
    echo"&nbsp;<input type=submit name=submzc value=注册>";
    echo "</td></tr></table>";
    echo "</form></td></tr></table>";?>
      

  3.   

    人家给的是js代码你不会在html里嵌php代码么
      

  4.   

    syre(神仙) :
    在PHP里不能嵌JS吗?
      

  5.   

    怎么嵌入js ,象我上面的代码中,要将js摆在何处,才能得到我想要的结果,就是验证无非法字符后,才提交给cl.php进行处理???
       小弟才刚开始学,别笑我,望各位前辈指点一二,小弟不胜感激!!!
      

  6.   

    在你的提交按钮的onclick事件中包含xuzuning(唠叨)的代码,最好写成函数,方便调用!
      

  7.   

    <script language=JavaScript1.2>function regcheck(formct){
    if (formct.userid.value=='' || formct.password.value==''){
    alert('会员名或密码为空,请填写');
    return false; 
    }

    if (/^[^a-z]$/g.test(formct.userid.value)){
    alert("userid 非法");
    return false;
    }
    if (/^[^a-zA-Z0-9]$/g.test(formct.password.value)){
    alert("password 非法");
    return false;
    }
    }
      

  8.   

    <script language=JavaScript1.2>function regcheck(formct){
    if (formct.userid.value=='' || formct.password.value==''){
    alert('会员名或密码为空,请填写');
    return false; 
    }

    if (/^[^a-z]$/g.test(formct.userid.value)){
    alert("userid 非法");
    return false;
    }
    if (/^[^a-zA-Z0-9]$/g.test(formct.password.value)){
    alert("password 非法");
    return false;
    }
    }