:: Personal website of a Toronto web designer
Lately » Validate Canadian postal codes in PHP
I spent a couple of hours writing a "simple" function that validates Canadian postal codes (something like M4J2L4). Anybody interested in how the function looks like? Any improvements?
:: Sasha, at 01:49 am on Friday, 27. September 2002
Any reason you didn't use Regular Expressions?
:: Jake Howlett, at 09:31 am on Friday, 27. September 2002
Well, no, ha ha. I could have done that :-)
Now I know why I didn't come to that idea. I was working with ASP whole day long. Believe me, I was mixing dots and ampersands :-)
:: Sasha, at 10:24 am on Friday, 27. September 2002
Guess it's more fun doing it without RegExp ;o)
For a real challenge have a go at UK postcodes. Never worked the pattern out myself.
Apparently the rules are:
1. The total length must be 6,7, or 8 characters, a gap (space character) must be included
2. The inward code, the part to the right of the gap, must always be 3 characters
3. The first character of the inward code must be numeric
4. The second and third characters of the inward code must be alpha
5. The outward code, the part to the left of the gap, can be 2,3, or 4 characters
6. The first character of the outward code must be alpha
Here are some examples:
NG17 3AR
W1 7TR
EC2M 4YR
etc
:: Jake Howlett, at 11:07 am on Friday, 27. September 2002
Huh, I am happy I didn't have to deal with those :-)
:: Sasha, at 11:44 am on Saturday, 28. September 2002
Useless scrawling facts:
Top 5 scrawlers:
(updated once a day)
556 Sasha
488 zoka
316 vitez-koja
235 Davor
58 mungos

