<script language="javascript">
function validate() {
document.getElementById("d1").innerHTML='';
var regdeptname = /[^\u4e00-\u9fa5]/g;
var deptname = document.getElementById("deptname").value;
if (!regdeptname.test(deptname)) {
alert('<font color="red">李毅</font>');
document.getElementById("deptname").focus();
return false;
}
return true
}
</script>
</head> <body>
<form action="" method="post">
<table border="1" width="600">
<tr>
<th colspan="2">
<span class="title">增加部门</span>
</th>
</tr>
<tr>
<td>
部门名称
</td>
<td align="left">
<input type="text" name="deptname" id="deptname"
onBlur="validate()" />
<span id="d1"></span>
</td> </tr>
<tr>
<td>
部门人数
</td>
<td align="left">
<input type="text" name="deptcount" id="deptcount" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</body>
</html>

解决方案 »

  1.   

    var regdeptname = /^[\u4e00-\u9fa5]+/g;<script language="javascript"> 
    function validate() { 
      document.getElementById("d1").innerHTML=''; 
      var regdeptname = /^[\u4e00-\u9fa5]+/g; 
      var deptname = document.getElementById("deptname").value; 
      if(!regdeptname.test(deptname)){ 
         alert('李毅');
         document.getElementById("deptname").focus(); 
         return false; 
      }
      return true;

    </script> 
    </head> <body> 
    <form action="" method="post"> 
    <table border="1" width="600"> 
    <tr> 
    <th colspan="2"> 
    <span class="title">增加部门 </span> 
    </th> 
    </tr> 
    <tr> 
    <td> 
    部门名称 
    </td> 
    <td align="left"> 
    <input type="text" name="deptname" id="deptname" 
    onBlur="validate()" /> 
    <span id="d1"> </span> 
    </td> </tr> 
    <tr> 
    <td> 
    部门人数 
    </td> 
    <td align="left"> 
    <input type="text" name="deptcount" id="deptcount" /> 
    </td> 
    </tr> 
    <tr> 
    <td colspan="2"> 
    <input type="submit" value="提交" /> 
    <input type="reset" value="重置" /> 
    </td> 
    </tr> 
    </table> 
    </form> 
    </body> 
    </html>