Jquery validate minlength rule not working

I have a form with a password field. Password must be at least 8 characters long.

<form action="/account/register" method="post" id="form-register"> <div class="input-row"> <input name="data[User][password]" type="password" id="FUserPassword" class="required" placeholder="Password"> </div> </form> $("#form-register").validate({ rules: { FUserPassword : { minlength: 8 } } }); 

It applies the "required" rule, but it just ignores the "minlength" rule.

What am I doing wrong? I use the same code (part of JS) on other pages and it works as expected.

+11
jquery jquery-validate
source share
2 answers

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

A pair of keys / values ​​that define custom rules. The key is the name of the item (or group of checkboxes / radio buttons)

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

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

To enter names with special characters, be sure to specify the object key.

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

+16
source share

I do not know why it does not work with values ​​greater than 254, I tried, but 254 is the maximum length value that the plugin can check.

0
source share

All Articles