【问题标题】:Jquery Validator not validating email ID created with random string with its email attributeJquery Validator 不验证使用随机字符串创建的电子邮件 ID 及其电子邮件属性
【发布时间】:2019-02-09 14:37:39
【问题描述】:

这行代码不适用于类似以下的电子邮件:akg@gol.red...???

$("#admin_forget").validate({rules: {email: {required: true, email: true}}});

所以,我创建了一个新方法并且它有效:

$.validator.addMethod("validate_email", function (value, element) {
     if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4est(value)) {
         return true;
     } else {
         return false;
     }
 }, "Please enter a valid email address.");
 $("#admin_login_form").validate({
     errorClass: "error-msg", rules: {
         email: {
             required: true,
           //email: true,
             validate_email:true
         }
     }
});

有没有办法使用默认方法而不是添加新方法?

【问题讨论】:

    标签: jquery validation email


    【解决方案1】:

    我想这可能对你有帮助。

    你可以修改你的正则表达式

    /^([\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3} .)|(([\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$/

    【讨论】:

      【解决方案2】:

      我不是 100%,但我很确定内置的验证器不接受“.red”作为域。它专门寻找常见的。我以前遇到过这个问题。无论如何,使用你自己的正则表达式可能会更好。

      【讨论】:

        猜你喜欢
        • 2012-11-25
        • 2014-12-25
        • 2018-07-30
        • 2011-08-12
        • 2015-02-24
        • 1970-01-01
        • 2015-09-09
        • 1970-01-01
        相关资源
        最近更新 更多