This is my code to update the jQuery validation dynamically. In document load i create the validation. This code is used to update the phone number validation dynamically. A
There are four potential problems.
1) You're missing a closing brace for the messages section.
$("#phone").rules("add", {
required: true,
phoneUS: true,
messages: {
required: "Enter company phone number",
phoneUS: "Enter valid phone number"
} //<-- this was missing
});
DEMO: http://jsfiddle.net/A8HQU/2
2) There is a known bug where adding messages using the rules('add') method breaks the plugin and/or rule. Make absolutely sure you are including jQuery Validate version 1.11.1 or better.
3) The phoneUS rule requires the inclusion of the additional-methods.js file.
4) The rules('add') method must come after the .validate() initialization function.
Note:
You're using the phoneUS rule, so minlength and maxlength are totally superfluous since the phoneUS rule is already looking for a precise format/length.