Dynamically modifying(read adding and removing) rules using jQuery validate
Got some hidden fields in a form which needs validation(at some later point say, when made visible)? Lets learn how to remove or add validation rules dynamically using jQuery Validate plugin.
We can use rules()
method of jQuery-validate
plugin to add and remove rules.
Here is how you can remove rules from any element
remove
is a string, specified for removing the rules and rules
are the space separated names of rules. This argument is optional, if left unspecified, it removes all the static rules.
Example:
Adding rules to the element is also quite simple
add
is a string, specified for adding the rules and rules
are the rules to add. These rules are specified in the same format as the rules-option of the validate-method.
Example:
Working Example: https://jsfiddle.net/lavika/vtme816s/
References: jQuery-validate()