How to Validate an Email Address in Node.JS

When accepting and processing information, such as email addresses, from outside sources, the margin for error on input text can be high. However, if you rely on this information to remain in contact with your clients or associates, you need to minimize as much of this risk as possible. The following APIs will help you validate given email addresses, the first specifically for reading syntax and the second for server existence, and the last for full validation including results concerning syntax and servers.

Image for post
Image for post

For all three APIs, you will first need to install our client software:

npm install cloudmersive-validate-api-client --save

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-validate-api-client": "^1.2.4"
}

Then, for our syntax-only API, you can call the following function:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveValidateApiClient.EmailApi();var value = "value_example"; // String | Email address to validate, e.g. \"support@cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.emailPost(value, callback);

If you would like to access our server-only API, you can call this function, EmailAddressGetServers:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveValidateApiClient.EmailApi();var email = "email_example"; // String | Email address to validate, e.g. \"support@cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.emailAddressGetServers(email, callback);

For our full validation API, call this next function, EmailFullValidation:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveValidateApiClient.EmailApi();var email = "email_example"; // String | Email address to validate, e.g. \"support@cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.emailFullValidation(email, callback);

Now, you can ensure whether all the contact data that you collect is accurate and leads to a server and an existing account. You can retrieve your personal API Key from the Cloudmersive website. This will give you access to up to 800 free calls per month across our library of APIs.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store