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 #182723 is a reply to message #182721] Sat, 31 August 2013 14:40 Go to previous messageGo to previous message
Fiver is currently offline  Fiver
Messages: 35
Registered: July 2013
Karma:
Member
On 2013-08-31 08:17, Gordon Burditt wrote:
>> 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?
[..snip..]
> 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.

If he had no reason to collect the postal codes at all, he wouldn't have
put them in the form (I hope). As soon as he does collect and store them
somewhere (like a database), for whatever purpose, he needs to do some
basic formal/plausibility checking.

This would be true even if he didn't limit the input to US and Canadian
codes. There are some general assumptions you can make about postal
codes that are valid everywhere in the world. For example

- no valid code will start/end with white space
- codes will never be longer than 20 characters
- codes without any alphanumeric characters are never valid

This is just basic data hygiene. I would never store user input without
at least checking the known formal constraints of the field.

The more he knows about the codes, the more he can check. This is where
the formal validation for the US/Canadian codes comes in. The general
format is known. If he has this information, he should use it, if only
to prevent some categories of typos.

Checking if a postal code is actually assigned to a real location at
this point in time, or if a certain delivery method is available to the
location - that's well outside the area of formal checks. If this level
of validation is required, he'll need an API from the delivery service
(or whoever is going to use the code). Then he needs to validate the
code at least twice: once on entry and once before sending out an actual
package.

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

Good advice.

> You might also exclude H0H 0H0, which is reserved for Santa Claus.

Just wondering... why does Santa Claus have a Canadian postal code?
The geographic north pole outside Canadian territory. If his house was
as close to the north pole as he can get while still remaining on firm
land, he should have a Danish postal code.

regards,
5er
[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: Mon Nov 25 02:45:03 GMT 2024

Total time taken to generate the page: 0.04183 seconds