Damien’s Blog

JavaScript – Block email domain

Posted by: damienhowley on: July 14, 2009

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

Leave a Reply

About Me

My name is Damien Howley and I am a graphic designer for MindTouch. I currently live in beautiful San Diego and I'm passionate about web 2.0, social media and user interface design. I also am interested in green technologies and companies that are implementing green policies and utilizing green practices.

Twitter: @DamienH
Linkedin: Damien Howley
Flickr: DamienHowley

Twitter Updates

Flickr Photos

Cox Cable TV is terrible

CIMG8732

CIMG8918

More Photos