Regex for Canadian Postal Code
This regex matches Canadian postal codes in the A1A 1A1 alternating letter-digit format. It excludes letters D, F, I, O, Q, and U, which are not used in Canadian postal codes to avoid confusion with similar-looking digits. The first letter indicates the province or territory. The optional space between the two three-character groups follows common formatting conventions.
^[A-CEGHJ-NPRSTVXY]\d[A-CEGHJ-NPRSTV-Z]\s?\d[A-CEGHJ-NPRSTV-Z]\d$ What is the regex pattern for Canadian Postal Code?
The regex pattern for Canadian Postal Code is ^[A-CEGHJ-NPRSTVXY]\d[A-CEGHJ-NPRSTV-Z]\s?\d[A-CEGHJ-NPRSTV-Z]\d$ with the i flag. This regex matches Canadian postal codes in the A1A 1A1 alternating letter-digit format. It excludes letters D, F, I, O, Q, and U, which are not used in Canadian postal codes to avoid confusion with similar-looking digits. The first letter indicates the province or territory. The optional space between the two three-character groups follows common formatting conventions. This pattern is commonly used for canadian address validation and province detection.
Test Examples
K1A 0B1 K1A 0B1 V6B 3K9 V6B 3K9 D1A 1A1 Common Uses
- ✓ Canadian address validation
- ✓ Province detection
- ✓ Shipping calculations
- ✓ Form input validation
Variations
Strict with space
^[A-CEGHJ-NPRSTVXY]\d[A-CEGHJ-NPRSTV-Z] \d[A-CEGHJ-NPRSTV-Z]\d$ Requires the space
First character only
^[A-CEGHJ-NPRSTVXY] Validates just the first character for province lookup
Simple format
^[A-Z]\d[A-Z]\s?\d[A-Z]\d$ No excluded letter checks
Frequently Asked Questions
Why are some letters excluded from Canadian postal codes?
Letters D, F, I, O, Q, and U are excluded to prevent confusion with digits 0, 1, and other similar-looking characters, especially in handwritten addresses and OCR scanning.
Can I determine the province from a postal code?
Yes, the first letter indicates the province or territory. For example, K is Ontario, V is British Columbia, H is Quebec (Montreal area), and T is Alberta.
Is the space required?
Canada Post officially formats postal codes with a space (A1A 1A1), but many systems store them without the space. This pattern accepts both formats.