标签:
</pre><div><pre name="code" class="html"><html> <head><title>Js 正则表达式之邮箱验证</title> <script> function checkEmail(){ //cedar_c@163.com.cn var emailObj = document.forms[0].email; var email = emailObj.value; var div = document.getElementById("aa"); var reg = /^\s*$/; if(reg.test(email)){ div.innerHTML="<font color=red>!邮箱不能为空</font>"; return false; } var reg = /^\w+@[\w-]+\.[a-zA-Z]+$/; if(!reg.test(email)){ div.innerHTML="<font color=red>!邮箱格式不正确</font>"; return false; } return true; } </script> </head> <body> <form onSubmit="return checkEmail()"> 邮箱:<input name="email" type="text"/><div style="display:inline" id="aa"></div> <br/> <input type="submit" value="确定" /> </form> </body> </html>
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/wei_chong_chong/article/details/47258785