I am using the jQuery Validation plugin for validating my form.
I want to validate the zip code as per US ZIPCode format :-
> 12345 > 12345-678
You can define a custom validator:
jQuery.validator.addMethod('zipcode', function(value, element) { return this.optional(element) || !!value.trim().match(/^\d{5}(?:[-\s]\d{4})?$/); }, 'Invalid zip code');
Then use it like this