Skip to content

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.

Pattern flags: i
^[A-CEGHJ-NPRSTVXY]\d[A-CEGHJ-NPRSTV-Z]\s?\d[A-CEGHJ-NPRSTV-Z]\d$
Test this pattern in the Regex Tester →

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

Match
K1A 0B1
Matches: K1A 0B1
Match
V6B 3K9
Matches: V6B 3K9
No Match
D1A 1A1

Common Uses

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.

Related Patterns

US ZIP Code

^\d{5}(-\d{4})?$

UK Postal Code

^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$

Related Reading

Regex Cheat Sheet with Examples for Developers → URL Encoding Special Characters →