正则表达式之邮箱验证
正则表达式之邮箱验证
在线演示: 验证 document.getElementById("emailyz").onclick=function(){ var email = document.getElementById("emailreg").value; console.log(email); var reg = /^([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)+((\.[0-9a-zA-Z_-]{2,3}){1,2})$/gi; var jieguo = reg.test(email); console.log(jieguo); if(jieguo == true){ document.getElementById("emailp").innerHTML="验证成功!" }else{ document.getElementById("emailp").innerHTML="验证失败!" } } 正则表达式 /^([0-9a-zA-Z-]+)@([0-9a-zA-Z-]+)+((.[0-9a-zA-Z_-]{2,3}){1,2})$/g 实现过程 完整代码 //小程序用户请移步网页端查看,原文链接https://hkiii.cn/?post=84; <body> <input style="width:100%;" id="emailreg" placeholder="请输入一个邮箱地址"/> <p id="emailp"> </p> <button id="emailyz">验证</button> </body> <script> document.getElementById("emailyz").onclick=function(){ var email = document.getElementById("emailreg").value; console.log(email); var reg = /^([0-9a-zA-Z_-]+)@([0-9a-zA-Z_-]+)+((\.[0-9a-zA-Z_-]{2,3}){1,2})$/gi; var jieguo = reg.test(email); console.log(jieguo); if(jieguo == true){ document.getElementById("emailp").innerHTML="验证成功!" }else{ document.getElementById("emailp").innerHTML="验证失败!" } } </script>
 3周前
     跳转到第 页,共 1 页

Theme By Brief 鄂ICP备19010459号
sitemap