Skip to content

Instantly share code, notes, and snippets.

@PhazeonPhoenix
Created March 9, 2012 20:21
Show Gist options
  • Save PhazeonPhoenix/2008475 to your computer and use it in GitHub Desktop.
Save PhazeonPhoenix/2008475 to your computer and use it in GitHub Desktop.
RegEx: US & Canadian Zip Code
# http://regexlib.com/REDetails.aspx?regexp_id=122
# This expression matches three different formats of postal codes: 5 digit US ZIP code, 5 digit US ZIP code + 4, and 6 digit alphanumeric Canadian Postal Code. The first one must be 5 numeric digits. The ZIP+4 must be 5 numeric digits, a hyphen, and then 4 numeric digits. The Canadian postal code must be of the form ANA NAN where A is any uppercase alphabetic character and N is a numeric digit from 0 to 9.
^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment