正则表达式, email格式验证,邮箱地址验证

函数

function checkEmail(email){
    if(email == null || email == ""){return true;}
    email = email.trim();
    if(email  == ""){return true;}

    var patt1 = /^[a-z,A-Z,0-9]+@[a-z,A-Z]+.[a-z,A-Z]+$/
    if(str.match(patt1) == null){
        return false;
    }
    return true;
    
}

调用:

if(checkEmail("[email protected]")){
 alert('格式正确');
}

if(!checkEmail("[email protected]")){
 alert('格式错误');
}

 

你可能感兴趣的:(正则表达式)