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 #182643 is a reply to message #182634] Tue, 20 August 2013 23:52 Go to previous messageGo to previous message
Norman Peelman is currently offline  Norman Peelman
Messages: 126
Registered: September 2010
Karma:
Senior Member
On 08/20/2013 01:27 PM, Twayne wrote:
> Hi all,
>
> I'm attempting to check for US and Canadian zip codes (postal codes).
> The US is easy; mostly just be sure it's five numerics and except
> "00000" and "99999". But Canadian is a different story because:
> It consists of alternating alpha and numeric characters (AnAnAn) but
> not the entire alphabet. 8 N.A. English letters are not used, as in
> DFIOQUW AND Z or put another way, they only use 18 letters in their
> postal codes.
> I haven't see a single example in all my research to check if the
> 1st, 3rd, and 5th characters are alpha and th 2nd, 4th and 6th
> characters are numeric.
>
> I've tried preg_match and strpos without succees, likely due to my own
> weakness with preg_match, and regex creates an incredibly long statement
> I'm sure it's not right to put upon the servers; they slow down even my
> local server XAMPP & PHP 5.3 on win 7.
>
> Might anyone have a better method?
>
> Or know of any functions anywhere that could be modified to be used?
>

US Zip code:
[0-9]{5}(-{0,1}[0-9]{4}){0,1}

Canadian zip code (all one line, don't miss the space!):
([A-C,E,G-H,J-N,P,R-T,V,X,Y]{1}[0-9]{1})[A-C,E,G-H,J-N,P,R-T,V,X,Y]{1}
{1}([0-9]{1}[A-C,E,G-H,J-N,P,R-T,V,X,Y]{1}[0-9]{1})


--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[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 10:45:37 GMT 2024

Total time taken to generate the page: 0.04542 seconds