Title |
Test
Find
U.S. and Canadian postal codes
|
Expression |
^((\d{5}-?\d{4})|(\d{5})|([A-Za-z]\d[A-Za-z]\s?\d[A-Za-z]\d))$ |
Description |
This expression more loosely 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 (optional), and then 4 numeric digits. The Canadian postal code must be of the form ANANAN where A is any alphabetic character (case insensitive) and N is a numeric digit from 0 to 9. A space between the 2nd "A" and 2nd "N" is optional but not required, so the form could also be interpreted as "ANA NAN" |
Matches |
90210, 90210-1234, 902101234, H0H0H0, h0h0h0, H0H 0H0, h0h 0h0 |
Non-Matches |
9021090210, California, ABC123, ABC 123, H0H H0H |
Author |
Rating:
Not yet rated.
Douglas Barbin
|
Source |
|
Your Rating |
|