Jquery plugin provides simple clientside form validation and offers some customization. It is a good choice if we are making something new from the scratch, not only this it also facilitates if we are trying to integrate something into our existing application. It contains lots of validation methods. All these methods come with some default error message, including url and email validation, while providing an API to write our own. The current version of is 1.17.0.
There are two ways to validate :
1. Method: It contains the logic to validate an element, like an email method that checks for the right format of the input element.
A couple of methods are available, and it is easy to write your own.
2. Rule: A validation rule related to an element with the validation method like validate input with name "any-email" with a method "required" and "email".
It contains three JQuery plugin methods, the main entry point validate method:
1. validate() - This method is used to validate the selected form.
2. valid() - This method checks whether the selected form or selected elements are valid
3. rules() - This method is used to read, add and remove rules for an element.
validate method returns validator object which contain few public methods that we can use in our validation.
few methods of validator are as follow:-
1. Validator.form() - It is used to validate the form.
2. Validator.element() - It is used to validate the single element.
3. Validator.resetForm() - It is used reset the controlled form.
4. Validator.showErrors() - It is used to show the specified error messages on invalid elements.
5. Validator.numberOfInvalids() - It is used to returns the number of invalid fields .
6. Validator.destroy() - It is used to destroy the instance of the validator.
There are some static method on the validator object:
1. jQuery.validator.addMethod() - It is used to add the custom validation method on form and element.
2. jQuery.validator.format() – It is used to replaces placeholder with argument input elements.
3. jQuery.validator.setDefaults() – It is used to modify default settings to validate .
4. jQuery.validator.addClassRules() – It is used to add a compound class method.