jquery validate minlength rule is not working

后端 未结 1 620
日久生厌
日久生厌 2021-02-20 06:45

I have a form with a password field. The password has to be at least 8 characters long.

1条回答
  •  你的背包
    2021-02-20 07:12

    Validate looks for the name of the input field, not the id. From the documentation for the rules option:

    Key/value pairs defining custom rules. Key is the name of an element (or a group of checkboxes/radio buttons)

    With that in mind, you should use something like this:

    $("#form-register").validate({
        rules: {
            'data[User][password]': {
                minlength: 8
            }
        }
    });
    

    For input names with special characters, be sure to quote the object key.

    Example: http://jsfiddle.net/kqczf/4/

    0 讨论(0)
提交回复
热议问题