<input type=text name=txt>
<input type=button value=check onclick=if(/\W/.test(txt.value))alert("非法字符")>

解决方案 »

  1.   

    for( var i=0;i<document.form.a.value.length;i++  ){
            var ch = document.form.a.value.charAt(i);
                    if(!((ch>='0'&&ch<='9')||(ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))){
                       alert("必须为字符!");
                       document.orm.a.focus();
                       return false;                }
             }
    虽然麻烦了一点儿,还是挺好用的
      

  2.   

    我一般都是用wuque007(阿华)的这种方法,呵呵