How to Validate an Email Address in JavaScript
Fully validating an email address can be a pain; you need to track down the mail server, contact the email server to validate the account’s existence, and check the syntax. Luckily, the following API will perform those tasks for you — all without sending any emails! This is a great tool to have working for you behind the scenes on your website or app.
To perform the validation in JavaScript, we first need to install the jQuery library:
bower install jqueryNow that the installation is complete, we can call the function:
var settings = {
"url": "https://api.cloudmersive.com/validate/email/address/full",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": JSON.stringify("<string>"),
};$.ajax(settings).done(function (response) {
console.log(response);
});
The response will return a wealth of information including the validity of the syntax, domain, and SMTP, as well as the server used for the validation request. To gain free access to 800 monthly calls across this and our entire library of APIs, simply register for an account on the Cloudmersive website.