By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Regexp way to detect PO Boxes?

P: n/a
Hi,

Does anyone have code that detects if a field has been entered in PO
Box format? I'm trying to prevent users from entering PO Boxes for
shipping addresses.

Thanks, - Dave
Jun 27 '08 #1
Share this Question
Share on Google+
13 Replies


P: n/a
laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
Does anyone have code that detects if a field has been entered in PO
Box format? I'm trying to prevent users from entering PO Boxes for
shipping addresses.
What country, what format?

If you ca give a reasonable definition of what is a PO-box string and what
is not, a regex test should be possible.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2

P: n/a
On Apr 24, 3:01*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
Does anyone have code that detects if a field has been entered in PO
Box format? *I'm trying to prevent users from entering PO Boxes for
shipping addresses.

What country, what format?

If you ca give a reasonable definition of what is a PO-box string and what
is not, a regex test should be possible.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
The country is the United States. My understanding of a PO Box is
that it is of the form PO Box #### where "#" is a number between 0 and
9. But the number of numbers could be unlimited, I suppose and there
could be variation in how "PO Box" is written, e.g. if punctuations
are included somewhere within. - Dave
Jun 27 '08 #3

P: n/a
laredotornado wrote:
On Apr 24, 3:01 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
Does anyone have code that detects if a field has been entered in
PO Box format? I'm trying to prevent users from entering PO Boxes
for shipping addresses.

What country, what format?

If you ca give a reasonable definition of what is a PO-box string
and what is not, a regex test should be possible.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

The country is the United States. My understanding of a PO Box is
that it is of the form PO Box #### where "#" is a number between 0 and
9. But the number of numbers could be unlimited, I suppose and there
could be variation in how "PO Box" is written, e.g. if punctuations
are included somewhere within. - Dave
Very simplistically the regex
/PO\s+Box\s+\d+/i
will work.

Try it out like this:
<script type="text/javascript">
<!--
var f = /PO\s+Box\s+\d+/i;
var q = 'Po Box 33';
alert(f.test(q));
// -->
</script>
Jun 27 '08 #4

P: n/a
laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
On Apr 24, 3:01*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
Does anyone have code that detects if a field has been entered in
PO Box format? *I'm trying to prevent users from entering PO Boxes
for shipping addresses.

What country, what format?

If you ca give a reasonable definition of what is a PO-box string and
what
>is not, a regex test should be possible.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

The country is the United States. My understanding of a PO Box is
that it is of the form PO Box #### where "#" is a number between 0 and
9. But the number of numbers could be unlimited, I suppose and there
could be variation in how "PO Box" is written, e.g. if punctuations
are included somewhere within. - Dave
t = 'pO box 123';

if (/^\s*po\s+box\s+\d+$/i.test(t)) alert('PO box detected');

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #5

P: n/a
Paul Lautman escribió:
Very simplistically the regex
/PO\s+Box\s+\d+/i
will work.
And with optional characters:

/P\.?O\.?\s+Box\s+#?\d+/i


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #6

P: n/a
Álvaro G. Vicario wrote on 25 apr 2008 in comp.lang.javascript:
Paul Lautman escribió:
>Very simplistically the regex
/PO\s+Box\s+\d+/i
will work.

And with optional characters:

/P\.?O\.?\s+Box\s+#?\d+/i
How right you are,
don't expand on the OP's definition,
or there will be no end to this thread.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #7

P: n/a
laredotornado wrote:
On Apr 24, 3:01 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
>>Does anyone have code that detects if a field has been entered in PO
Box format? I'm trying to prevent users from entering PO Boxes for
shipping addresses.
You can ask users not to enter shipping addresses with PO boxes (or,
more plausibly, only use street addresses for shipping addresses). And
you can attempt to verify that the addresses they enter do not include
PO boxes (or are street addresses).

But you cannot prevent them from entering addresses with PO boxes
unless you can determine exactly what USPS, or whatever shippers you
use, will treat as an address with a PO box. And since addresses are
interpreted by people, that will be difficult.
The country is the United States. My understanding of a PO Box is
that it is of the form PO Box #### where "#" is a number between 0 and
9. But the number of numbers could be unlimited, I suppose and there
could be variation in how "PO Box" is written, e.g. if punctuations
are included somewhere within.
This specification is decidedly incomplete.

In my experience, USPS, for example, will treat any of the following
as referring to a PO box:

PO Box 123
P.O. box 123
PO Box #123
Box 123
Box no. 123
#123 [if there's no street address]

Frankly, if you addressed a letter to:

Smith
123
01945

and mailed it in the US, and the Marblehead, Massachusetts post office
(zip code 01945) happened to have a box 123 owned by someone named
Smith, it would very likely be delivered there.

Shippers are typically fairly aggressive in deciphering addresses;
that's good for business.

So barring getting a strict specification from all of your shippers,
and implementing it (both unlikely), the best you can do is provide
some heuristics. My initial suggestion would be: if the first address
line with a series of digits does not have anything after the digits,
it's probably a box number.

That accepts (identifies as a box) any of the examples above, while
rejecting (identifying as a street address) cases like:

123 5th [an address on 5th Street]
123 Main #3 [an address with an apartment number]

and so forth. Assuming you've already identified the line of text that
might be a box number, the regex:

/^\D*\d+$/

would identify offending entries. (It says: start at the beginning of
the string and scan until you find a series of digits. Is there
anything after those digits? If not, then we have a match.)

My recommendation: if you implement this, and you get a match, alert
the user that it *appears* they have supplied a PO box, and that PO
boxes are not allowed, and let them change *or keep* their entry. If
you get a false positive, you don't want to prevent the user from
submitting valid data. Better to take invalid input and have a person
correct it later (by contacting the user or whatever).

--
Michael Wojcik

Jun 27 '08 #8

P: n/a
In comp.lang.javascript message <3854e688-ef70-412d-bae4-fa01f174ae4f@k1
3g2000hse.googlegroups.com>, Thu, 24 Apr 2008 12:18:02, laredotornado
<la***********@zipmail.composted:
>Does anyone have code that detects if a field has been entered in PO
Box format? I'm trying to prevent users from entering PO Boxes for
shipping addresses.
That sounds like what the Army used to refer to as a thunderbox, for
example on the North-West Frontier. WSC was no doubt familiar with the
item.

Remember when posting here that you are a foreigner. You should,
therefore, avoid non-standard local abbreviations and should not assume
knowledge of your locally-preferred formats, especially as you don't
indicate your location.

But we do have still Post Office Boxes here (I think).

There's then the question of whether a Post Office Box, or functional
equivalent, is necessarily abbreviated to PO Box. I doubt whether that
form comes naturally in, say, Russia, France, or PQ. But, if you are an
American, you are probably not considering the rest of the world at all,
except perhaps Canada.

You should probably strip all punctuation from the field first, and any
instance of the word "no", and #. Use .replace for that, with a RegExp.
--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Jun 27 '08 #9

P: n/a
VK
On Apr 25, 3:09 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Remember when posting here that you are a foreigner.
Is c.l.j. under Her Majesty's jurisdiction? I was not aware of it -
when did it happen?

It is a RegExp question with OP's spelled pattern to seek. If you have
nothing productive to say about it, then why polluting the infospace
with unrelated crap?

To OP: be aware that many services (Mail & More to name one) for extra
payment providing P.O. boxes with real mailing addresses, so it will
be like "Anytown, Any St. 123, suite #456" with "Anytown, Any St. 123"
being the address of the Mail & More office and #456 being your P.O.
box cell. This way consider "no P.O." check - either client or server
side - as a nice add-on but not a decisive tool for important
commercial decisions.
Jun 27 '08 #10

P: n/a
In comp.lang.javascript message <96473fa2-f959-49c6-8467-e2f107524c50@x3
5g2000hsb.googlegroups.com>, Fri, 25 Apr 2008 13:51:10, VK
<sc**********@yahoo.composted:
>On Apr 25, 3:09 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
>Remember when posting here that you are a foreigner.

Is c.l.j. under Her Majesty's jurisdiction? I was not aware of it -
when did it happen?
Typical VK mental inadequacy. Everyone posting here is a foreigner, to
at least most of those reading. In practice, everyone except Americans
realises that when posting, and writes accordingly. That is one reason
why you are liable to be taken as an American yourself.
>It is a RegExp question with OP's spelled pattern to seek. If you have
nothing productive to say about it, then why polluting the infospace
with unrelated crap?

To OP: be aware that many services (Mail & More to name one) for extra
payment providing P.O. boxes with real mailing addresses, so it will
be like "Anytown, Any St. 123, suite #456" with "Anytown, Any St. 123"
being the address of the Mail & More office and #456 being your P.O.
box cell. This way consider "no P.O." check - either client or server
side - as a nice add-on but not a decisive tool for important
commercial decisions.
The OP will no doubt, after reading the group, know what value to put on
your opinions.
Actually, there should be no reasonable objection to having a PO Box
included together with a real address; there may be a practical need for
a real address, though that is discriminatory against anyone who has no
reliable address or who has good reasons not to give it. The correct
approach must be to ask for a real, or other sufficient address; and to
let the customer subsequently suffer the consequences of getting it
wrong.

--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Jun 27 '08 #11

P: n/a
VK
On Apr 26, 6:29 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Remember when posting here that you are a foreigner.
Is c.l.j. under Her Majesty's jurisdiction? I was not aware of it -
when did it happen?

Typical VK mental inadequacy.
Typical Dr. Stockton's fallacy covered by "you cannot speak the
language properly". A foreigner:

"1. a person not native to the country or jurisdiction under
consideration; alien."
c.l.j. is not a country - and coming to the jurisdiction, however
silly it would be - it is run by NNTP servers all around the globe. So
not that I guess.

"2. a person from outside one's community."
uhm... so outside one's community where P.O. abbreviation is not known
and not welcome to discuss: by Dr. Stockton's strong opinion. It is
not clear though how did Dr. Stockton determine the nature of the
community? Maybe it is right apposite one's community where a person
not knowing or pretending do not know what P.O. is, being a dork?

Unsurprisingly I understood what you were trying to say: long years
of practice of reading your poor English :-)

"Remember when posting here that this newsgroup being read by people
from different countries where P.O. meaning and functionality may be
not known".

However silly and paternalistic such comment would be, at least it is
closer to the conventional English.

Still OP provided the exact search pattern he'd like to have, so even
if someone would be misfortune enough do not know what P.O. is, it is
completely irrelevant to the problem. The question could be even like
"I want to sort out whatchamacallit, for this I have to detect strings
like..."
In practice, everyone except Americans
realises that when posting, and writes accordingly. That is one
reason why you are liable to be taken as an American yourself.
I am an American but I am not a native English speaker. If I don't
understand the matter of some post I simply avoid answering to it. You
might accommodate this useful practice as well.
Actually, there should be no reasonable objection to having a PO Box
included together with a real address
FedEx and some other express services do not deliver to P.O. boxes.
Mailing insurance cost varies for real addresses and for P.O.

Again: why are you trying to talk about matters which are completely
alient to you. Do not forget: you are a foreigner.
;-)
Jun 27 '08 #12

P: n/a
In comp.lang.javascript message <b317d5b1-65f1-4a37-a0fc-cd56e18a91a1@l6
4g2000hse.googlegroups.com>, Sat, 26 Apr 2008 11:10:03, VK
<sc**********@yahoo.composted:
>I am an American but I am not a native English speaker.
Very few of them are; they use a different language but call it the
same.
If I don't
understand the matter of some post I simply avoid answering to it.
That is evidently not a common opinion among your readers here.
>Actually, there should be no reasonable objection to having a PO Box
included together with a real address

FedEx and some other express services do not deliver to P.O. boxes.
Mailing insurance cost varies for real addresses and for P.O.
If given a PO Box and a real address, they can deliver to the real
address. Also, the OP will be able to omit any such address at the
server end.

Over-rigorous checking at the client end can easily alienate or stop
possible customers. One should reject, at most, only what certainly
cannot be handled at the server end.

Many Americans consider Canadians, unlike other foreigners, to be so
near human as to treat them in the same manner as they treat other
Americans; for example, they use the same international dialling code.
Therefore, it may well be that the OP would be willing to trade with
even the rather strange form of Canadians that are found in Quebec. If
so, his processing may need to look for Boite Postale numbers; a
francophone might use that term even if it is not nationally standard.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htmclpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.htmlnews:borland.* Guidelines
Jun 27 '08 #13

P: n/a
Dr J R Stockton wrote on 27 apr 2008 in comp.lang.javascript:
If
so, his processing may need to look for Boite Postale numbers; a
francophone might use that term even if it is not nationally standard.
French is by some convention the international post/mail language.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.