javascript check if email is valid 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: email regex javascript
/* Answer to: "email regex javascript" */
ValidateEmail("[email protected]"); // Must be a string
function ValidateEmail(email) {
var emailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(String(email).toLowerCase());
if (email.match(emailformat)) {
alert("Nice Email!")
return true;
};
alert("That's not an email?!")
return (false);
};
Example 3: validate email javascript
function validateEmail(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 4: js check if email is valid
function ValidateEmail(mail)
{
if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(myForm.emailAddr.value))
{
return (true)
}
alert("You have entered an invalid email address!")
return (false)
}
Example 5: how to validate an email address in javascript
function validateEmail(email)
{
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
console.log(validateEmail('[email protected]'));
Example 6: regex for email validation
//Author: Mohammad Arman Khan
//Regular Expresssion for e-mail validation
var email_validator_regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;