Reputation: 11875
i need to validate the account number, it can be either 6 number (111111), or two letter then 6 numbers (xx111111).
Can someone please show me how to do it? thank you.
Upvotes: 2
Views: 100
Reputation: 126042
As @Teja says, you need to use .addMethod
with a regular expression. I believe this should work:
$.validator.addMethod("accountnumber", function(value, element) {
return this.optional(element) || /^(\w{2})?\d{6}$/.test(value);
}, "Please enter a valid account number");
$("#form").validate({
rules: {
account: {
accountnumber: true
}
}
});
Example: http://jsfiddle.net/andrewwhitaker/tUaB7/
Upvotes: 4
Reputation: 17472
Use the addMethod method on the validation plugin as shown in the example and modify the regex to match your criteria..
Upvotes: 0