I need to provide the P.O Box validation for the address Fields in the registration page. Now we have a regex validation in jquery which has some limitations as follows:
- If an address polo Rd is given, it identifies "po" in polo and alerts error message.
So, we should frame a new validation which should not accept address lines with the values:
"PO BOX"
,"PO BIN"
,"BIN"
,"P.O BOX"
,"P.O BIN"
,"P.O"
,"PO"
- the above values can be in any case
- spaces before, in between and after the above words should also be found and validated. For example:
" P O 1234 "
should be validated and alert error message. - But
"Polo Rd"
,"Robin Rd"
,"testbintest"
should be accepted as valid address in both the address lines.
The code right now in jquery validation is:
jQuery.validator.addMethod("nopobox", function(value, element) {
return this.optional(element) || ! /(P(OST)?\.?\s*O(FF(ICE)?)?\.?\s*(?<!(BOX)|(BIN)))|(^[^0-9]*((P(OST)?\.?\s*O(FF(ICE)?)?\.?)|(?<!(BOX)|(BIN))))/i.test(value);
}, "");