<!DOCTYPE html> <html> <head> <title>检测邮箱名</title> <Meta charset="utf-8"> </head> <body> <input type="test" name="" id="email" > <!--设置Email输入框--> <input type="button" name="" value="检测合法性" onclick="checkEmail()"> <!--checkEmail后不要忘了()--> <script type="text/javascript"> function checkEmail(){ var objStr = document.getElementById("email").value; //不要忘了.value var objReg = /\w+[@]{1}\w+[.]{1}\w+/; if(objReg.test(objStr)){ alert("输入的邮箱是符合标准的"); }else{ alert("输入的邮箱不符合标准"); } } </script> </body> </html>
正则表达式可参考:
http://blog.csdn.net/leledexixi/article/details/54831141
原文链接:https://www.f2er.com/regex/358595.html