且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查电子邮件地址是否不是“免费网络邮件”。 (hotmail,雅虎...)

更新时间:2023-02-25 10:23:56

首先,我建议不要这样做。因为雅虎提供高级PAID服务(我自己使用它并且会很烦恼如果你不允许我注册)。

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).

你还需要在客户端(JS)和服务器上实现(PHP,ASP.net或者你正在使用的任何东西),因为我可以轻松禁用Javascript,然后你的支票就不会执行了。

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.

代码:

// get index of '@'
var index_at = email.indexOf('@');

// get index of the '.' following the '@' and use it to get the real domain name
var domain = email.substring(index_at + 1,  email.indexOf('.', idx));

// now use the domain to filter the mail providers you do not like

检查所有子域的代码(对于abc@subdomain.hotmail.com):

Code to check all sub-domains (for abc@subdomain.hotmail.com) :

// get the string after '@'
var after_at = email.substring(email.indexOf('@') + 1);

// get all parts split on '.', so for abc@x.y.z you can check both x and y
var dot_split = after_at.split('.');
for(var i = 0; i < dot_split.length; i++)
    // check each dot_split[i] here for forbidden domains