In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章主要介绍如何使用正则表达式验证身份证号码和邮箱、判断checked选中状态,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
项目中正好写到登录注册,在用blur事件验证用户输入内容的时候,出现了点bug,最后是在注册按钮onclick的事件里获取用户输入值来验证的。
判断checked选中状态:
if(!$('#checkedAgree').prop("checked"){ console.log('no');//未选中 }else{ console.log('yes');//选中 } //注册 $(".regBtn").on('click',function(){ var regUser = $('#regUser').val();//用户名 var regPass = $('#regPass').val();//密码 var regAgainpass = $('#regAgainpass').val();//确认密码 var regTrueName = $('#regTrueName').val();//真实姓名 var idNumber = $('#idNumber').val();//身份证 var email = $('#email').val();//邮箱 if(!regUser){ alert("用户名为空,请输入用户名"); }else if(!regPass || regPass.length < 6){ alert("密码为空或长度少于6位,请输入正确的密码"); }else if(!regAgainpass || regAgainpass != regPass){ alert("确认密码为空或两次密码输入不一致,请输入正确的密码"); }else if(!regTrueName){ alert("真实姓名为空,请输入真实姓名"); }else if(!idNumber || !idNum(idNumber)){//调用身份证验证方法 alert("身份证号码不正确,请输入正确的身份证号码"); }else if(!email || !emailNum(email)){//调用邮箱验证方法 alert("邮箱不正确,请输入正确的邮箱email"); }else if(!$('#checkedAgree').prop("checked")){//判断用户同意注册协议状态 alert("您还未同意用户注册协议"); }else{ console.log('yes'); //some code here } }); //身份号码验证 function idNum(idNum){ var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if(!reg.test(idNum)){ return false; }else{ return true; } } //邮箱验证 function emailNum(emailNum){ var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;//验证身份证号 if(!reg.test(emailNum)){ return false; }else{ return true; } }以上是"如何使用正则表达式验证身份证号码和邮箱、判断checked选中状态"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.