日期:2014-05-16  浏览次数:20457 次

js 验证特殊字符
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <script language="javascript">
 
  function isCheckNumber(){
   var numbercard=document.forms[0].num.value; 
var numberpattern =/^[A-Za-z0-9_]{1,8}$/;
      if(!numberpattern.test(numbercard)){
   alert("请输入有效的 只能是1-8位数字,字母或数字字母的组合");
   document.forms[0].num.focus();
         return false;
       }
return true;
}
 
 
  </script>
</HEAD>

<BODY>
  <form>
 
  number:<input type="text" name="num" id="num" onblur="isCheckNumber()" value=""/>
 
  </form>
</BODY>
</HTML>