How to validate email addresses with javascript

Check if an email address is correct and really exists using standard javascript and jquery

You can easily test if an email address is formatted correctly with a regex, like in the example bellow. But it will miss many important cases, like if the email address is well formed but the emails will bounce, because the account never existed or has recently been disabled.

pattern_regex_test.js
if (/[^@]+@[^@]+\.[^@]+/.test("foo@bar.com")){
// email matches the pattern
} else {
// email doesnt match the pattern
}

Real email API validation

To do full email validation inspecting the mail server you can use isitarealemail.com and make a requests call to check it. This will do the check via the real email service which will make sure the requests are not blocked.

real_email_validation_jquery.js
var emailAddress = "foo@bar.com"
var apiKey = ???
$.ajax("https://isitarealemail.com/api/email/validate?email=" +
emailAddress,
{
crossDomain: true,
headers: {
Authorization: "Bearer " + apiKey
}
})
.then(function responseHandler(data) {
if (data.status === 'valid') {
console.log("the email is valid and the mail box is active")
} else {
console.log("the email is incorrect or unable to be tested.")
}
});

Get started with real email validations today.