本文介绍了检查电子邮件地址是否不是“免费网络邮件”。 (hotmail,雅虎...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改:我的网站仅向Gmail和Google Apps用户提供服务,并希望确保其他免费电子邮件用户在启动oauth配对时不会收到错误消息。

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.

所以这是交易:我要么弄清楚这是Gmail / Google Apps地址,要么试图阻止热门免费邮件用户尝试订阅。

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.

我想阻止所有属于Gmail,Hotmail,Yahoo等的免费电子邮件地址...来自我的网站订阅。

I want to prevent all "free" email addresses that belongs to Gmail, Hotmail, Yahoo, etc... from subscribing in my website.

我怎样才能在javascript中正确执行此操作?
这是我开发的第一个脚本:

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");     
} 

但它没有检测到电子邮件,如[email protected][email protected]

But it doesn't detect email like [email protected] or [email protected].

你能帮忙吗?非常感谢!

Could you please help? Thanks a lot!

推荐答案

首先,我建议不要这样做。因为雅虎提供高级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

检查所有子域的代码(对于[email protected]):

Code to check all sub-domains (for [email protected]) :

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

// get all parts split on '.', so for [email protected] 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

这篇关于检查电子邮件地址是否不是“免费网络邮件”。 (hotmail,雅虎...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 18:19