只允许特定的电子邮件地址域通过JQuery注册(最好) [英] Allow only specific email address' domain to register through JQuery (preferably)
问题描述
我想要注册表格,我只想在特定网域的电子邮件中注册。例如,我想只注册来自companyX,companyY,companyZ的电子邮件。
因此,可接受的电子邮件将是: -
- myname@companyZ.com
- myname@companyY.com
- myname@companyX.com
有什么想法如何在JQuery中执行?
更新
这是我写的,现在上了
$ b if(
(preg_match(/ ^ \S+@companyX\.com$/i,$ input)||
(preg_match(/ ^ \S + @ companyY\.com $ / i,$ input)||
(preg_match(/ ^ \S+@companyZ\.com$/i,$ input)
){
}
else {
//错误。
}
b $ b
感谢
电子邮件只包含一个@,因此您可以拆分输入值第二部分
str = str.split('@')。slice(1);
然后只需检查是否在您可接受的列表中
var allowedDomains = ['x.com','y.com','z.com'];
if($ .inArray(str [0],allowedDomains)!== -1){
//可接受
} else {
//不可接受
}
这是一个jsfiddle中的工作示例: http://jsfiddle.net/UwmYK/2/ 只需输入电子邮件并点击运行。
I am trying to make registration form within which I want to register only with specific domains' emails. For e.g. I want to register only the emails which are from the companyX, companyY, companyZ.
Hence the acceptable emails would be:-
- myname@companyZ.com
- myname@companyY.com
- myname@companyX.com
Any idea how to do it in JQuery?
Update
This is what I wrote, uptill now
($input)
if (
(preg_match("/^\S+@companyX\.com$/i", $input) ||
(preg_match("/^\S+@companyY\.com$/i", $input) ||
(preg_match("/^\S+@companyZ\.com$/i", $input)
) {
}
else {
//Error.
}
Thanks
An email is only going to contain one @ so you could split the input value and take the second part
str = str.split('@').slice(1);
then simply check if that is in your acceptable list
var allowedDomains = [ 'x.com', 'y.com', 'z.com' ];
if ($.inArray(str[0], allowedDomains) !== -1) {
//acceptable
}else{
//not acceptable
}
here is a working example in a jsfiddle: http://jsfiddle.net/UwmYK/2/ just type in the email and click run.
这篇关于只允许特定的电子邮件地址域通过JQuery注册(最好)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!