javascript regex for email domain code example
Example 1: javascript regex email
function validateEmail (emailAdress)
{
let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (emailAdress.match(regexEmail)) {
return true;
} else {
return false;
}
}
let emailAdress = "[email protected]";
console.log(validateEmail(emailAdress));
Example 2: js email regex
function isValidEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
Example 3: email id domain check javascript
var myemail = '[email protected]'
if (/@yahoo.com\s*$/.test(myemail)) {
console.log("it ends in @yahoo");
}