博客园  :: 首页  :: 联系 :: 管理

javascript-利用正则表达式检查电子邮件格式

Posted on 2010-03-18 09:20  sunrack  阅读(609)  评论(0)    收藏  举报

//Check Email Format
function CheckEmail(theform)
{
email=theform.rs_email.value;
if(email=="")
{
alert("邮箱地址不能为空!");
theform.rs_email.focus();
return false;
}
else
{
   var re = /^[\w.-]+@([0-9a-z][\w-]+\.)+[a-z]{2,3}$/i;  

    if(re.test(email))
    {
        return true;
    }
    else
    {
  alert("邮箱地址格式不正确!");
  theform.rs_email.focus();
        return false;
    }
}
}