How to validate email addresses in Javascript

Cloudmersive
2 min readMar 12, 2020

--

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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet