I need a basic validation on postcode that is display error if empty and also display error if it matches the given value.
var zip_cde = "1234,5095,2356";
postcode: {
required: true,
number: true,
minlength: 4
},
<input type="text" name="postcode" id="postcode" placeholder="5095" >
i want that if the postcoe matches the zip_cde, jquery validator shall display error.
Any help is really appreciated.
var zip_cde = "1234,5095,2356";
postcode: {
required: true,
number: true,
postalcode: true
},
jQuery.validator.addMethod("postalcode", function(postalcode, element) {
return this.optional(element) || (postalcode.match(/^([0-9]{4})$/) && $.inArray(postalcode, zip_cde));
}, "Please enter a valid postcode");
<input type="text" name="postcode" id="postcode" placeholder="5095" >