Javascript Regular Expressions Validate Email

Description

Javascript Regular Expressions Validate Email

function isValidEmail(emailAddress) {
    let emailRegExp = /^(([^<>()\[\]\\.,;:@"\x00-\x20\x7F]|\\.)+|("""([^\x0A\x0D"\\]|\\\\)+"""))@(([a-z]|#\d+?)([a-z0-9-]|#\d+?)*([a-z0-9]|#\d+?)\.)+([a-z]{2,4})$/i;
    return emailRegExp.test( emailAddress );           
}
let email = "info@java2s.com";

if (isValidEmail(email)) {
    console.log("Valid Email Address");
} else {/*from   w  w w.jav a2  s . c o m*/
    console.log("Invalid Email Address");
}

function isEMailAddr(str) {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        return false;
    } else {//from  w  w  w .j  a va  2s  .co m
        return true;
    }
}
console.log(isEMailAddr("asdfa@meail.com"));
console.log(isEMailAddr("@meail.com"));
console.log(isEMailAddr("asdfa@.com"));
console.log(isEMailAddr("asdfa@meail."));
console.log(isEMailAddr("asdfa@meail.com"));



PreviousNext

Related