蓝烨科技
潍坊网站开发中心
在JS中使用正则表达式验证电子邮箱
<input type="text" id="email" name="email">
<input type="button" value="验证" onclick="isEmail('email')">
   <script language="javascript">
function isEmail(email) {
var strEmail=document.getElementById(email).value;
   if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
{
   alert("Email格式正确!");
   return true;
   }else{
     alert("Email格式不正确!");
     document.getElementById(email).value="";
     document.getElementById(email).focus();
     return false;
    }
}
</script>
posted on 2009-09-08 15:19  风无忌  阅读(1031)  评论(2编辑  收藏  举报