Js 过滤特殊字符

时间:2022-12-19 17:28:07
<body>
     <script   language= "JavaScript ">
          function check(str) {
               var pattern = /^[a-z\d\u4E00-\u9FA5]+$/i;
               if (pattern.test(str))
                    alert( "输入正确:只包含中文、字母、数字 ");
               else
                    alert( "错误:含有符号 ")
          }
     </script>
     <input type = "text" id = "txt" value = "">
     <input type = "button" onclick = "check(txt.value)" value = "Check">
</body>