编写自己定义的JavaScript函数checkEmail(),在该函数中首先推断E-mail文本框是否为空,然后在应用正則表達式推断E-mail地址是否合法,假设不合法提示用户
<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">