PHP: Form validation, Canadian Postal Code
Validating a Canadian postal code in PHP can be done with a simple Regular Expression. PHP’s preg_match function will return 0 (no match) or 1 (if there are 1 or more matches). To validate a Canadian postal code, you can use the following:
$value = 'A1B 2C3'; // Postal Code to validate
preg_match("/^[a-zA-Z][0-9][a-zA-Z] ?[0-9][a-zA-Z][0-9]$/", $value);
Note that the letters may be upper case or lower case.
More validation routines will follow.
No TweetBacks yet. (Be the first to Tweet this post)




January 3rd, 2009 at 7:14 am
hi nice site thx
January 21st, 2009 at 1:44 pm
Nice php preg match regex for canadian postal code ! I really appreciate !