I am using form validation plugin and using regular expression to validate UK post code. I am using This reference regular expression in which author says that it can validate all post code. But when i try to submit the form , for every kind of string it says invalid. I have tried the following (samples taken from wikipedia Here is page
W1A 1HQ
EC1A 1BB
M1 1AA
B33 8TH
Here is my JS code
$(document).ready(function(){
$.validator.addMethod("regex", function(value, element, regexp) {
var re = new RegExp(regexp);
console.debug(re.test(value))
return this.optional(element) || re.test(value);
},
"Post code is not valid"
);
$("#addPropertyForm").validate({
rules : {
postCode : {
required : true,
regex: "(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})"
}
},
messages : {
postCode : {
required : 'Post code is required',
}
},
onkeyup: false,
onblur: true,
focusCleanup: true,
focusInvalid: false
});
});
Can any one kindly help me what is wrong with this code