Last active
October 27, 2018 02:54
-
-
Save bjpeterdelacruz/9785713240428aa93ac685cf8be00037 to your computer and use it in GitHub Desktop.
Regular Express for P.O. Box Addresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Credit: https://github.com/EpicVoyage/pobox-regex */ | |
var pos = $(this).val().search(/(?:P(?:ost(?:al)?)?[\W\s]*(?:(?:O(?:ffice)?[\W\s]*)?B(?:ox|in|\b|\d)|o(?:ffice|\b)(?:[\W\s]*\d)|code)|b(?:o*x|i*n)[\W\s\b]*\d)|(?:P+[\W\s]*O+[\W\s]*)/i); | |
if (pos >= 0) { // P.O. box address was entered, so disable Submit button and display warning message | |
$("#submit_primary").attr("disabled", true); | |
if ($("#element_2_warning").length == 0) { | |
var text = "<div class='alert alert-warning' style='font-size: 12pt' id='element_2_warning'><strong style='color: #FF0000'>"; | |
text = text + "Street Address only, no P.O. Box.</strong></div>"; | |
$(text).insertBefore($("#li_2")); | |
} | |
$("#element_2_warning").show(); | |
} else { // not a P.O. box address, so enable Submit button and hide warning message | |
$("#submit_primary").removeAttr("disabled"); | |
$("#element_2_warning").hide(); | |
} | |
/* | |
The regex matches the following: | |
123 P O Box | |
123 P... O 456 | |
123 PO 456 | |
biin 123 | |
bin 123 | |
bn 123 | |
boox 123 | |
box 123 | |
bx 123 | |
Box-123 | |
Box-- 123 | |
Box123 | |
P O box 123 | |
p-o box 123 | |
p-o-box 123 | |
P. O. Box 123 | |
P.o box 123 | |
P.O. Box 123 | |
p.o. Box123 | |
p.o.-box 123 | |
P.O.B 123 | |
P.O.B. 123 | |
P.O.Box 123 | |
PO Biin 123 | |
PO Bin 123 | |
PO Bn 123 | |
PO Boox 123 | |
PO Box 123 | |
PO Bx 123 | |
PO-Box 123 | |
po-box123 | |
PO. Box 123 | |
pob 123 | |
pob123 | |
Pobox 123 | |
pobox123 | |
Post Box #123 | |
post box 123 | |
post office 123 | |
Post Office Bin 123 | |
post office box 123 | |
Postal Box 123 | |
Postal Code 123 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment