Re: Zip Codes ctype? Pregmatch? [message #182651 is a reply to message #182647] |
Wed, 21 August 2013 22:53 |
bill
Messages: 310 Registered: October 2010
Karma:
|
Senior Member |
|
|
On 2013-08-21 7:25 AM, Jeff North wrote:
> On Tue, 20 Aug 2013 13:27:50 -0400, in comp.lang.php Twayne
> <nobody(at)spamcop(dot)net>
> <kv08v0$614$1(at)speranza(dot)aioe(dot)org> 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?
>
> Try this (I found it on the web but can't remember where) and I
> haven't tired it out:
> ^[ABCEGHJ-NPRSTVXY]{1}\d{1}[A-Z]{1}\s?\d{1}[A-Z]{1}\d{1}$
>
lol! I'll be happy to check it out! :) I never did get my own to work,
and that's a bit different from what I used.
Twayne`
|
|
|