I need to provide the P.O Box validation for the address Fields 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);
}, "");
The new code designed is partially working like its taking
Polo road
Testbintest
But its throwing an error for
Robin road
Robox road
The below is the new code which is partally working
jQuery.validator.addMethod("nopobox", function(value, element) {
return ! /(?:p(?:ost)?\.?\s?[o|0](?:\.|ffice)?)\b|(?:b(?:[o|0]x)|(?:in))\b/i.test(value);
}, "PO Boxes are not allowed.");