【发布时间】:2017-09-17 12:13:49
【问题描述】:
我想知道您是否可以接受电子邮件地址的任何扩展名。而不是特定的域名扩展名。
例如
foo@surrey.ac.uk
foo@survey.ac.uk
这是我的代码。这是可行的,但问题是如果您为电子邮件 ac.uk 添加了扩展名,它不会接受它。例如,如果我注册了一个电子邮件 foo@ac.uk,它可以工作,但如果你尝试为电子邮件添加扩展名,如 foo@surrey.ac.uk 或 foo@survey.ac.uk,它不接受它。我希望它添加任何扩展才能正常工作。谢谢你们!
//for custom email
jQuery.validator.addMethod('customemail', function(value, element) {
var s=value;
var split = s.split('@');
var regex = /^([a-zA-Z0-9_.+-])+$/;
var s2="ac.uk"; //The split array is the domain excluding the @
var optionalValue = this.optional(element); //This is how other methods in alternativeMethods.js Validator handle this.
//Debugging - This is useful to see visually what is happening
//alert(split[0]); // Shows the inputted username i.e chris or smokey
//alert(split[1]); // Shows the inputted domain
//alert(regex.test(split[0])); //Shows unfilled inputs problem or bad characters, true if good, false if bad
//alert(s2 == split[1]);** // Shows if the inputted domain matches variable s2, if it does we get a true
if (optionalValue) {
return optionalValue;
}
if(regex.test(split[0]) && (s2 == split[1])) // has to be == not equals
{
return true;
}
else
{
return false;
}
}, 'Please specify a Verified Email');
有人将此查询报告为与此帖子 Email validation using jQuery 重复的查询
但我的问题有所不同,因为我需要一个经过批准的域扩展。不是一般的电子邮件验证
【问题讨论】:
-
你好@Jim 我认为这不是一个重复的问题。我在问一个需要不同域添加扩展的特定问题。我也不擅长java脚本,因为我还是个学生。但如果你能帮我解决我的问题,我会很高兴。
-
抱歉,乍一看似乎是一样的。这是部分匹配。
标签: javascript php jquery email