标签:正则表达式 javascript
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">编写自定义的JavaScript函数checkEmail(),在该函数中首先判断E-mail文本框是否为空,然后在应用正则表达式判断E-mail地址是否合法,如果不合法提示用户</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="javascript"><script type="text/javascript"> function checkEmail(){ var email = document.getElementById("email"); if(email.value == null || email.value == ""){ alert("请输入E-mail地址!"); email.focus(); return; } var regExp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; if(!regExp.test(email.value)){ alert("您输入的E-mail地址不正确!"); email.focus(); return; } } </script><span style="white-space:pre"> </span>
标签:正则表达式 javascript
原文地址:http://blog.csdn.net/qq_22605739/article/details/46437531