gpt4 book ai didi

javascript - 检查电子邮件地址是否不是 "free webmail"(hotmail、yahoo...)

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:52:58 27 4
gpt4 key购买 nike

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

事情是这样的:要么我试图弄清楚这是一个 Gmail/Google Apps 地址,要么试图阻止流行的免费邮件用户尝试订阅。

我想阻止所有属于 Gmail、Hotmail、Yahoo 等的“免费”电子邮件地址在我的网站上订阅。

我怎样才能在 javascript 中正确地做到这一点?这是我开发的第一个脚本:

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

但它不会检测像 test@hotmail.co.il 或 test@subdomain.hotmail.com 这样的电子邮件。

你能帮忙吗?非常感谢!

最佳答案

首先,我建议不要这样做。由于雅虎确实提供高级付费服务(我自己正在使用该服务,如果您不允许我注册,我会很生气)。

此外,您还需要同时在客户端 (JS) 和服务器上实现(PHP、ASP.net 或您正在使用的任何工具),因为我可以轻松禁用 Javascript,并且您的检查不会然后执行。

但是,如果您知道自己在做什么并希望正确完成,请先查找“@”,然后查找以下“.”。并获取它们之间的字符串。

代码:

// 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):

// 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

关于javascript - 检查电子邮件地址是否不是 "free webmail"(hotmail、yahoo...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8271578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com