How to validate email addresses in Javascript

Dealing with invalid email addresses is annoying and a drain on resources and time. The solution is a validation algorithm, of course. We will not be approaching this in an orthodox manner, with coding from scratch and all that. Instead, we will be hitting the problem from a different, and much easier, angle. Let’s get started

So we first must import our API client before we can do much else. Open your HTML file and past in this script tag to begin the process.

<script src="https://cdn.cloudmersive.com/jsclient/cloudmersive-validate-client.js"></script>

Once that is done, just use this code snippet here to call our email validation function:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';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);

And our email validation is set to go! When you test it out, you will notice that some additional information is provided, such as the server queried, syntax test results, etc.

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