虚位以待(AD)
虚位以待(AD)
首页 > 网页特效 > JavaScript > js邮箱验证,正则表达式验证邮箱

js邮箱验证,正则表达式验证邮箱
类别:JavaScript   作者:码皇   来源:互联网   点击:

单个邮箱的验证方法: function checkEmail() { var emailValue=document getElementById_r( "email ") value; if (!isEmail(emailValue)) { alert( "您输入的邮箱有误,请重新核对后再输入! "); document getElementById_r( "email ")

正则表达式验证邮箱

单个邮箱的验证方法:

    function checkEmail() {
    var emailValue=document. getElementById_r("email").value;
    if (!isEmail(emailValue)) {
    alert("您输入的邮箱有误,请重新核对后再输入!");
    document. getElementById_r("email").focus();
    return false;
    }
    return true;
    }
    function isEmail(str){
    var reg = /^(w)+(.w+)*@(w)+((.w+)+)$/;
    return reg.test(str);
    }
多个邮箱,中间用“;”隔开的验证方法:

    //验正邮箱格式要正确 20080602_heyitang var email=document. getElementById_r("trans_email").value;
    //如果,用户入了邮箱才需要进行判断 if (email!=null) {
    if (email.indexOf(";
    ")==-1) {
    if(!isEmail(email)) {
    alert("您输入的单个邮件格式有误,请重新核对后再输入");
    document. getElementById_r("trans_email").focus();
    return false;
    }
    }
    else {
    var emailArray=email.split(";
    ");
    for(i=0;
    i<emailArray.length;
    i++) {
    //这里防止出现heyitang@qq.com;
    heyitang@163.com;
    ;
    多加了;
    这时候,数组中可能有元素没有内容 if(emailArray[i]!=null || emailArray[i]!="") {
    if(!isEmail(emailArray[i])) {
    alert("您输入的多个邮箱格式中有邮箱格式不 正确,请重新核对后再输入");
    document. getElementById_r("trans_email").focus();
    return false;
    }
    }
    }
    }
    }


(责任编辑:网页模板)
相关热词搜索: js邮箱验证 正则表达式验证邮箱