How to validate email addresses in Javascript

Our free API to validate e-mail addresses is really easy to use in Javascript

 

Validate e-mail in JavaScript with jQuery

How to validate an email address in jQuery.


var settings = {
	"async": true,
	"crossDomain": true,
	"url": "https://mailcheck.p.rapidapi.com/?domain=EMAIL-OR-DOMAIN",
	"method": "GET",
	"headers": {
		"x-rapidapi-host": "mailcheck.p.rapidapi.com",
		"x-rapidapi-key": "YOUR-API-KEY"
	}
                            }

$.ajax(settings).done(function (response) {
	console.log(response);
});
                

 

This will return a JSON-array with information about the domain, and if you should block it or not.

 

Validate e-mail in JavaScript with fetch()

How to validate an email address in plain javascript.


fetch("https://mailcheck.p.rapidapi.com/?domain=EMAIL-OR-DOMAIN", {
	"method": "GET",
	"headers": {
		"x-rapidapi-host": "mailcheck.p.rapidapi.com",
		"x-rapidapi-key": "YOUR-API-KEY"
	}
                            })
.then(response => {
	console.log(response);
})
.catch(err => {
	console.log(err);
});
                

 

Validate e-mail in JavaScript with XMLHttpRequest

How to validate an email address in plain javascript.


var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
	if (this.readyState === this.DONE) {
		console.log(this.responseText);
	}
                            });

xhr.open("GET", "https://mailcheck.p.rapidapi.com/?domain=EMAIL-OR-DOMAIN");
xhr.setRequestHeader("x-rapidapi-host", "mailcheck.p.rapidapi.com");
xhr.setRequestHeader("x-rapidapi-key", "YOUR-API-KEY");

xhr.send(data);
                

 

You can of course just send it as a regular GET-request to that URL also, in your favorite way, as long as you have the API-key in the header.

You will receive a JSON response, telling you if this is a disposable e-mail to block, or if there are other issues with the domain:

 


{
   "valid": true,
   "block": true,
   "disposable": true,
   "domain": "backlinkcity.info",
   "text": "Disposable e-mail",
   "reason": "Heuristics (1b)",
   "risk": 91,
   "mx_host": "mx37.m1bp.com",
   "mx_info": "Unable to connect to MX on port 25",
   "mx_ip": "192.110.255.242",
   "last_changed_at": "2020-06-11T09:56:02+02:00"
}
               

 

This will tell you if you should block the domain backlinkcity.info or not, and the reason to why the API thinks so (disposable e-mail, etc). You can also see more detailed documentation of the response here.

To get started for free, and get an API key, click here!