Why is jQuery Validation adding noValidate attribute?

The novalidate attribute simply tells the browser to disable the built-in HTML5 validation, or ignore any HTML5 validation attributes you may have used.

The jQuery Validate plugin dynamically adds the novalidate attribute because, by installing it, you’ve decided to let the plugin handle validation instead of HTML5.

Neither of those two methods, JavaScript (jQuery) or HTML5, are good enough for protecting your database. You should always have some kind of server-side validation in place for when client-side validation fails, is disabled, or bypassed by the user/browser.

Quote OP:

” My form is rendered with the attribute noValidate and therefore I can insert null/empty values into the database.”

Sounds like something is very wrong with the way you’re using the jQuery Validate plugin, and the novalidate attribute is not the root cause.

If it’s critical that you cannot enter null data, you’ll need data validation code on the server side to prevent this. You must never rely on client-side code to protect the database since all client-side code can be easily bypassed.

“What is the reasoning for this?”

As explained above. This is normal and desired. The plugin simply uses novalidate to take over client side validation from the browser (HTML5).

If you have no HTML5 validation attributes, then the novalidate attribute, or lack of novalidate attribute, does absolutely nothing. In other words, it only toggles the HTML5 validation if you use HTML5 validation attributes.

“Does the form have to be set up in a particular way?”

Yes. But we cannot see your markup to tell where you went wrong.

“My dirty work around is using: .removeAttr('novalidate')

This is not smart, or completely superfluous, depending on your markup. Effectively, you are potentially allowing HTML5 validation to occur simultaneously with the jQuery Validate plugin. Pick one or the other for client-side validation.


The OP has since added some HTML markup to the question.

The jQuery Validate plugin is working exactly as expected: http://jsfiddle.net/tv7Bz/

Leave a Comment