P.O. Box Validation -- Hans?...Steve(Guru)?

S

Simple Simon

Hi,
I need some help getting this P.O. Box regular expression to work, or
a new expression entirely. I got this one from a Google Groups
search. It seems to work at: http://regexlib.com/ but not at runtime.

I need to check if a P.O. Box exists in an address text box...UPS
won't ship some items to a P.O. Box.

ValidationExpression="(?i)^((?<!P\.?\s?O\.?\sBox).)+(?<!P\.?\s?O\.?\sBox)$"

Please help?

TIA,
~Gordon
 
B

Brian W

Actually, I think you will find that UPS won't ship _ANYTHING_ to a P.O. Box

Keep in mind also, as you suggest this is valid:

P O Box 123

but so are these:

P.O. Box 123
PO Box 123
P O Box 123
Box 123
#123

(I'm sure I missed some combinations)

You will have to check for each one as may vary from person to person.

In addition UPS may ship to:

132 Main Street
Box 123
Anytown, USA

as it may be a Mailbox Etc. (now UPS Store) store

Just some extra food for thought


Good luck
Brian W
 
Joined
Oct 9, 2011
Messages
1
Reaction score
0
This Java method should work.
/**
* The below are the possible combinations P.O.BOX, PO.BOX, P O BOX, P O B O
* X, POBOX, PO BOX, P.O.B.O.X
*
* @param input
* @return true if the input value = pobox else false
*/
public static boolean checkPoBox(String input) {
boolean poBox = false;
String inputVal = input;
try {
if (input.length() > 4) {
inputVal = inputVal.replace(".", "").replace(" ", "")
.toLowerCase();
if (inputVal.contains("pobox")
|| inputVal.equalsIgnoreCase("pobox")) {
poBox = true;
}
}
} catch (Exception e) {
log.debug("Exception from checkPoBox");
}
return poBox;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top