Regexp way to detect PO Boxes?

L

laredotornado

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
 
E

Evertjan.

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.
 
L

laredotornado

laredotornado wrote on 24 apr 2008 in comp.lang.javascript:


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.

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
 
P

Paul Lautman

laredotornado said:
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>
 
E

Evertjan.

laredotornado wrote on 24 apr 2008 in comp.lang.javascript:
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');
 
E

Evertjan.

Álvaro G. Vicario wrote on 25 apr 2008 in comp.lang.javascript:
Paul Lautman escribió:

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.
 
D

Dr J R Stockton

In comp.lang.javascript message <3854e688-ef70-412d-bae4-fa01f174ae4f@k1
3g2000hse.googlegroups.com>, Thu, 24 Apr 2008 12:18:02, laredotornado
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.
 
M

Michael Wojcik

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).
 
V

VK

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.
 
D

Dr J R Stockton

In comp.lang.javascript message <96473fa2-f959-49c6-8467-e2f107524c50@x3
5g2000hsb.googlegroups.com>, Fri, 25 Apr 2008 13:51:10, VK
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.
 
V

VK

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.
;-)
 
D

Dr J R Stockton

In comp.lang.javascript message <b317d5b1-65f1-4a37-a0fc-cd56e18a91a1@l6
4g2000hse.googlegroups.com>, Sat, 26 Apr 2008 11:10:03, VK
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.
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.
 
E

Evertjan.

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top