无论是正确的姓名还是不正确的姓名都匹配不到
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="#" method="post" id="frmInfo">
<div id="error" style="color: red"></div>
<div>
姓名 :<input id="name" name="name" />
</div>
<div>
身份证:<input id="idno" name="idno" />
</div>
<div>
<input type="submit" />
</div>
</form>
<script type="text/javascript">
document.getElementById("frmInfo").onsubmit=function(){
//在JS中定义正则表达式对象只需要在/正则表达式/
regex1=/^[\u4e00-\u9fa5]{2,8}$/;
regex2=/^[1234568]\d{16}[0-9xX]$/
var name=document.getElementById("name").value;
var idno=document.getElementById("idno").value;
if(regex1.test(name)==false);{//利用正则校验数据,true代表匹配,false代表不匹配
document.getElementById("error").innerHTML="无效姓名";
return false;
}
else if(regex1.test(idno)==false){
document.getElementById("error").innerHTML="无效身份证号";
return false;
}
else{
alert("验证通过,准备提交")
return true;
}
}
</script>
</body>
</html>
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧