JavaScript验证中文,特殊字符

<head>
<title>验证只能为中文</title>
<script language="javascript">
function check(){
var t = document.forms[0].elements["text1"];
if (t.value != t.value.replace(/[^\u4E00-\u9FA5]/g,'')){
   alert("不全是中文");
}
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="button" name="btn" value="提交" onclick="check()" />
<input type="text" name="text1" />
</form>
</body>
</html>
作者:wpf之家
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/wpf123/p/2347466.html