JavaScript – Block email domain

Do you have forms on your website for people to submit sales information? Do you get personal email addresses when you’re looking for business email addresses? Blocking the personal email addresses can be very advantageous to your sales process and can provide a much needed filter on the leads coming in.

Here’s a nice JavaScript function that validates the domain of an email address against a list of predefined blacklisted domains. You add more domains simply add another item to domarray.   For instance you could have:

domarray[3] = “microsoft.”;

Additionally you can validate the domains as specific as possible:

domarray[3] = “gmail.jp”;
domarray[4] = “gmail.co.uk”;
domarray[5] = “gmail.kr”;

The Whole Script

function chckDomain(em) {
var emat = em.substring(0,em.lastIndexOf(‘@’)+1);
var emdom = em.substring(emat.length,em.length+1);
var emdom = emdom.toLowerCase();
var domarray = Array();
domarray[0] = “gmail.”;
domarray[1] = “hotmail.”;
domarray[2] = “yahoo.”;
for (i=0; i < domarray.length ; i++) {
if (emdom.indexOf(domarray[i]) != -1) {
return false;
}
}
return true;
}

Enjoy

Damien
@DamienH

Advertisements

2 responses to “JavaScript – Block email domain

  1. gr888888888888888………

    thanks a lot….

  2. Nice work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s