Edit: My Website is offering a service to Gmail and Google Apps users only, and do wanted to make sure that others free email users doesn’t get an error message when they initiate the oauth pairing.
so here is the deal : either I try to figure out that’s a Gmail/Google Apps address, or try to prevent popular free mail users from trying to subscribe.
I want to prevent all “free” email addresses that belongs to Gmail, Hotmail, Yahoo, etc… from subscribing in my website.
How can I do that correctly in javascript?
Here a first script I have developped :
var domain_matche = /@(.*)$/.exec(email);
var domain_name = domain_matche[1].substring(0, domain_matche[1].indexOf(".", 0))
if (domain_name == "hotmail" || domain_name == "yahoo" ) {
alert("not a valid email");
}
But it doesn’t detect email like test@hotmail.co.il or test@subdomain.hotmail.com.
Could you please help? Thanks a lot!
First of all, I would recommend do not do this. As yahoo does offer a Premium PAID service ( I am using that myself and would be annoyed a lot If you did not allow me to register).
Also you would need to implement on both client (JS) and Server (PHP, ASP.net or whatever you are using), as I could easily disable Javascript, and your check would not be executed then.
But if you know what you are doing and want it done properly, Look for first ‘@’ then the following ‘.’ and get the string between them.
Code:
Code to check all sub-domains (for abc@subdomain.hotmail.com) :