FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Zip Codes ctype? Pregmatch?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Zip Codes ctype? Pregmatch? [message #182721 is a reply to message #182634] Sat, 31 August 2013 06:17 Go to previous messageGo to previous message
gordonb.qnlcm is currently offline  gordonb.qnlcm
Messages: 1
Registered: August 2013
Karma:
Junior Member
> I'm attempting to check for US and Canadian zip codes (postal codes).

For what purpose? The reason I ask is that the type of checking you
do may depend on the reason for the checking.

What do you want to do with the (US) ZIP code? (a) Mail them a
first-class letter, (b) Mail them a package, (c) Use it as verification
for the billing address on a credit card (which is about equivalent
to (a) but the credit card company does the actual mailing), (Note:
validating a credit card transaction against a payment processor
often costs real money, so it is often desirable to verify the Luhn
checksum on the credit card number, check the number of digits vs.
the bank prefix, and validate the address at least for a valid
country and state/province before sending it to the payment processor.)
(d) figure out how far it is for them to drive to one of your stores,
or (e) Use it to figure out the country since it's too hard to ask
for it? If you're checking because some standard requires you to,
name the standard (and preferably the section). If you're checking
because, well, er, um, I dunno, you're supposed to check user input,
aren't you? maybe you need to review what it is you're trying to
accomplish.

If your requirement is to check because you want to check, you don't
care WHAT you check, you just wanna check! You WANNA! You WANNA!
You WANNA! then I have to wonder if the whole project should be
dropped.

For the USA, there are 5 types of 5-digit ZIP codes (and you
need a database that's kept up to date for determining this):

Unassigned. There are references to 42,000 codes being allocated
(as of 2011), so the majority of the 100,000 possible codes are
unassigned. 00000 and 99999 are permanently unassigned but only
the tip of a very large iceberg. (Usually, unassigned codes are
not assigned a type; they are just left out of the list entirely.)

Standard. These are geographic ZIP codes covering an area, what you'd
normally think of as a ZIP code area.

Post Office. These are ZIP codes with an area covering only part
of the inside of a USPS Post Office (PO boxes, caller services,
etc.) Typically a given PO Box has a unique 9-digit ZIP code. As
a test, I once mailed a letter to "Jeff Snerfelbot" (not anywhere
close to my name) with a 9-digit zip code of a PO box. It arrived.

Unique. Some 5-digit ZIP codes are allocated to a single entity
that generates or receives lots of mail. For example, Wal-Mart
Stores has 72716 and the CIA has 20505. It is rumored that Publisher's
Clearing House has at least 2 5-digit ZIP codes, one for "YES" and
one for "NO".

Military. These are used to route mail to US military forces,
including those stationed outside the country.

The Unassigned ZIP codes are clearly invalid.

The Standard and Unique ZIP codes are valid for most purposes.

If you are planning on using UPS or FedEx, the Post Office ZIP codes
are probably invalid, since they are filled with PO Boxes in USPS
Post Offices.

If you are planning on sending something bulky, the Military ZIP
codes may be invalid. They may have special rules on what you can
send.

A ZIP code may change. I was in 2 zip code splits near Houston,
Texas around Feb. 1976 where the apartment I moved out of and the
house I moved into both changed (5-digit) ZIP codes. 9-digit
codes hadn't been put to use yet.

Private mail box services generally appear in a Standard ZIP code
and UPS or FedEx can probably deliver there if the address looks
like a street address.

A valid address doesn't avoid the possibility that (a) it's an empty
lot, and has always been an empty lot, (b) it's unoccupied, or (c)
it burned down years ago. Someone might rebuild. The Post Office
might eventually invalidate addresses taken over for a freeway
interchange or for which soil erosion and/or a hurricane has placed
it permanently underwater.


You probably should accept a 9-digit ZIP code as well, even if you
ignore the extra 4 digits beyond checking that they are digits,
especially if part of the purpose is country recognition.

If your requirements are to (1) accept what is or may become a valid
code in the near future, and (2) must not require periodic database
updates, then I suggest you figure out what the basic pattern is
and check that. Be liberal in what you accept, as you can't fully
predict the future.

The USA is easy. Rejecting 00000 and 99999 is simple, and you don't
worry about the other 57,998 or so codes that might get used in the
future.

Unless you can find a general specification for Canadian Postal
codes, *NOT* what's currently in use, you're probably better off
allowing A-Z everywhere a letter is currently allowed. Is there
anything around that says that an asterisk won't become part of a
valid Canadian Postal code? or telephone number? There are
supposedly some codes reserved for testing. Those you can exclude.
You might also exclude H0H 0H0, which is reserved for Santa Claus.

On the other hand, if your requirements are to (1) eliminate as
many bad codes as possible, and (2) a database subscription to
issued codes is acceptable, and (3) an occasional rejection of brand
new codes is acceptable, then you want to find an API preferably
maintained by someone else to do the checking for you.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Where's the error?
Next Topic: Xml Loading special Characters
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 09:31:04 GMT 2024

Total time taken to generate the page: 0.04930 seconds