用JS验证输入必须为中文为什么输入是中文还是一直弹提示

蓝德库洛尔多 蓝德库洛尔多 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
贴代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="gbk">
<title>Insert title here</title>

</head>
<body>
<div align="center">
<form action="sub.jsp" method="post" onsubmit="return toVaild();" >
用户名:<input type="text" id="user" /><br />
密码:<input type="password" id="password" /><br/>
姓名:<input type="text" id="first" /><br/>
男性:<input type="radio" checked="checked" id="Sex" name="m" value="male" /><br />
女性:<input type="radio" id="Sex" name="m" value="female" /><br/>
编号:<input type="text" id="no" /><br/>
电话号码:<input type="text" id="phone" /><br/>
身份证号码:<input type="text" id="IDcard" /><br/>
邮箱地址:<input type="text" id="email" /><br/>
籍贯:
<select name="jiguan">
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="广州">广州</option>
<option value="深圳">深圳</option>
</select><br/>

<input type="submit" id="submit" value ="提交"/>
<input type="reset" name="button" id="button" value="重置"/>
</form>
</div>
</body>
<script type="text/javascript">

function toVaild(){
var user1 = document.getElementById("user");
var password1 = document.getElementById("password");
var first1 = document.getElementById("first");
var no1 = document.getElementById("no");
var phone1 = document.getElementById("phone");
var IDcard1 = document.getElementById("IDcard");
var email1 = document.getElementById("email");
var reg=/[\u4E00-\u9FA5\uF900-\uFA2D]/;
if(user1.value==null || user1.value==""){
alert("请输入用户名");
user1.focus();
return false;
}
if(password1.value==null ||password1.value==""){
alert("请输入密码");
password1.focus();
return false;
}
if(first1.value==null ||first1.value==""){
alert("请输入姓名");
first1.focus();
return false;
}
if(!reg.test(first1)){
alert("请输入汉字");
return false;
}

if(no1.value==null ||no1.value==""){
alert("请输入编号");
no1.focus();
return false;
}
if(phone1.value==null ||phone1.value==""){
alert("请输入电话号码");
phone1.focus();
return false;
}
if(IDcard1.value==null ||IDcard1.value==""){
alert("请输入身份证号码");
IDcard1.focus();
return false;
}
if(email1.value==null ||email1.value==""){
alert("请输入电子邮件地址");
email1.focus();
return false;
}




return true;
}



</script>
</html>
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
蓝德库洛尔多
JavaScript 87,984 成员 224,680 内容