Validationflags: gi
Canadian Postal Code
Match Canadian postal codes in the A1A 1A1 or A1A1A1 format with valid first-letter prefixes.
Try it in RegexProPattern
regexJavaScript
/[ABCEGHJ-NPRSTVXY]\d[A-Z] ?\d[A-Z]\d/giRaw source: [ABCEGHJ-NPRSTVXY]\d[A-Z] ?\d[A-Z]\d
How it works
The leading character is constrained to letters actually used by Canada Post (D, F, I, O, Q, U, W, Z are excluded). Alternating letter-digit pattern, with an optional space separator.
Examples
Input
K1A 0B1Matches
K1A 0B1
Input
M5V3L9Matches
M5V3L9
Input
12345No match
—Common use cases
- Canadian address form validation
- Shipping label generation
- Geographic data cleaning
- E-commerce checkout for CA customers