jQuery Validate plugin requires a name attribute

Remember that no matter how you declare your rules when using jQuery Validate, even if you target by id and declare with the .rules('add') method, you must absolutely have a name attribute on any form element you wish to validate.

<input name="firstName" type="text" ...

See the Markup recommendations section of the Reference docs page:

“The name attribute is ‘required’ for input elements, the validation plugin doesn’t work without it.”

Why? The name attribute is how the jQuery Validate plugin keeps track of the inputs internally. Even though the documentation doesn’t specify it, it only stands to reason that if this is how the plugin is keeping track of everything, you must make sure each name is unique.

Leave a Reply

Your email address will not be published. Required fields are marked *