Unobtrusive Validation means without writing a lot of validation code, you can perform simple client-side validation by adding the suitable attributes and including the suitable script files.
These unobtrusive validation libraries need to be added:
Bower: bower install jquery-validation
NuGet: Install-Package jQuery.Validation
NPM : npm i jquery-validation
Installation via Package Managers:
- data-val-required=”This is required.”
- data-val-email=”Error message”
- data-val-maxlength=”Error message”
- data-val-maxlength-max=”Maximum length (e.g. 5)”
- data-val-minlength=”Error message”
- data-val-minlength-min=”Minimum length (e.g. 2)”
List of some data validation attribute:
Method for unobtrusive validation:
Firstly, we need to add those libraries in the script of HTML files. These libraries provide a list of data attributes (data-val, data-val-required, and many more) for validation. Then the form should be built according to the requirements in which different types of data attributes can be used.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.