我想这样做,但不知道如何在JavaScript中做到这一点.
if (Email == "*aol.com" || Email == "*hotmail*" || Email == "*gmail*" || Email == "*yahoo*")
{
alert("No Hotmail, Gmail, Yahoo or AOL emails are allowed!");
return false;
}
Run Code Online (Sandbox Code Playgroud)
有什么方法吗?
首先,我认为您的搜索有点过于通用.(例如,如果有人有电子邮件地址," shotmail@mydomain.com "?
试试这个:
var notAllowed = /@(?:aol|hotmail|g(?:oogle)?mail|yahoo)\.com$/i;
// You may want to cover other domains under .co.uk etc.
if ( notAllowed.test(emailAddress) ) {
alert("No Hotmail, Gmail, Yahoo or AOL emails are allowed!");
return false;
}
Run Code Online (Sandbox Code Playgroud)
我不得不问,你为什么禁止人们使用这些电子邮件地址?(不感兴趣)
此外,这真的应该在服务器端完成(我假设你没有使用SSJS)