<input
 onkeypress="return /[0-9a-zA-Z\u4E00-\u9FA5]/g.test(String.fromCharCode(event.keyCode))"
 onpaste="return !clipboardData.getData('text').match(/[0-9a-zA-Z\u4E00-\u9FA5]/)"
 ondragenter="return false"
>

解决方案 »

  1.   


     hrong(黄蓉): 你好,谢谢你的指教。
    不过 〈〉!〉〈·¥》这些符号还是能够输入,这些都是中文全角字符。怎么禁止掉?还有我想让用户可以输入 _ 也就是英文的下划线。谢谢!
      

  2.   

    <input
     onkeypress="return /[\w\u4E00-\u9FA5]/g.test(String.fromCharCode(event.keyCode))"
     onpaste="return !/[^\w\u4E00-\u9FA5]/g.test(clipboardData.getData('text'))"
     ondragenter="return false"
    >
    现在可以输入下划线了, 不过 〈〉!〉〈·¥》我这边测试不能输入呀!
      

  3.   

    不好意思! 我这边测试不够严格, 好象汉字输入时不会触发 onkeypress 事件:<form name=form1>
    <input name=txt
     onkeydown="oldValue=value; setTimeout('mm()')"
     onpaste="return !/[^\w\u4E00-\u9FA5]/g.test(clipboardData.getData('text'))"
     ondragenter="return false"
    ></form><SCRIPT LANGUAGE="JavaScript">
    var oldValue;
    function mm()
    {
      with(document.form1.txt)
        if(/[^\w\u4E00-\u9FA5]/g.test(value)) value = oldValue;
    }
    </SCRIPT>