【问题标题】:Jquery validation plugin code for password containing at least 10 characters, 1 number or punctuation, 1 upper and 1 lowercase.用于密码的 Jquery 验证插件代码,至少包含 10 个字符、1 个数字或标点符号、1 个大写和 1 个小写。
【发布时间】:2017-06-20 10:35:58
【问题描述】:

我正在尝试使用 jquery 验证插件验证我的表单以达到以下条件:

密码必须:

至少 8 个字符

至少包含一个大写字母和至少一个小写字母

至少包含一个数字或标点符号

我正在使用以下 jquery 插件: https://jqueryvalidation.org/

在这里我开始了一些代码,但无法编写完整的代码。请帮我完成以上密码条件。

        var form3 = $('#change_password_form');

        form3.validate({

            rules: {
                npassword: {
                    required: true,
                    minlength: 10
                },

                ncpassword: {
                    required: true,
                    equalTo:'#npassword'

                },
            },
            submitHandler: function (form) {

                success3.show();

                error3.hide();

                form.submit();
            }

        });

【问题讨论】:

    标签: jquery validation


    【解决方案1】:

    试试这个

    添加方法

    $.validator.addMethod(
            "regex",
            function(value, element, regexp) {
                var re = new RegExp(regexp);
                return this.optional(element) || re.test(value);
            },
            "Please check your input."
    );
    

    现在您需要做的就是验证任何正则表达式:

    $("#Textbox").rules("add", { regex: "((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,8})" })
    

    这个正则表达式用于

    (                   # Start of group
        (?=.*\d)        #   must contain at least one digit
        (?=.*[A-Z])     #   must contain at least one uppercase character
        (?=.*\W)        #   must contain at least one special symbol
           .            #     match anything with previous condition checking
             {8,8}      #        length at least 8 characters and also maximum of 8
    )                   # End of group
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-28
      • 2019-08-07
      • 2017-02-24
      • 2012-09-28
      • 2011-12-12
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多