jQuery.js:
Well, this one is an obvious dependency.
jQuery.validate.js:
Is a library that lets you validate forms easily without the need to write the actual validation logic and event handling yourself (as it comes bundled with many 'adapters' such as required
, digits
, min/max
etc), it will automatically prevent form submission and will display the appropriate error message.
For example:
$('#myForm').validate({
rules: {
fullname: { required: true, minlength: 5 },
age: { digits: true, maxlength: 2 },
}
});
jQuery.validate.unobtrusive.js:
Unobtrusive validation is aiming at sparing you from the need to explicitly set each element's validation rules in an imperative manner but rather lets you define the rules in a declarative way using data-*
attributes.
It is called 'unobtrusive' because it lets you write semantic HTML without adding an 'intrusive' <script>
tags for each element's desired rules.
For example:
<input type="text"
name="fullname"
data-val="true"
data-val-required="fullname is required"
data-val-length="minimum 5 characters"
data-val-length-min="5" />