【发布时间】:2015-01-06 21:22:49
【问题描述】:
我使用这种方法进行了 .edu 电子邮件验证 - jQuery Form Validation, Only Allow .EDU Email Addresses
但我想将两者合二为一,而不只是 .edu 或 .edu.nn(其中 nn 是 2 位国家代码)。无法弄清楚如何实现这一目标。 下面是同时接受 .edu 和 .edu.fr 的代码 - 除了 .edu 之外,我还需要接受所有其他 2 位国家代码
感谢您的帮助!
$.validator.addMethod("edu", function (value, element, param) {
// Make it work optionally OR
// Check the last 4 and 7 characters and ensure they match .edu and .edu.2-digit-country-code
return (this.optional(element) || value.slice(-4) == ".edu" || value.slice(-7) == ".edu.fr");
}, "Please enter valid .edu email address");
$("#requestform").validate({
rules: {
email: {
required: true,
email: true,
edu: true
},
}
});
【问题讨论】:
-
您是否打算拥有一组有效的国家代码?如果不只是删除最后一个条件,或者更改它以检查最后 2 个字符是否仅为字母
标签: javascript jquery jquery-validate