Skip to content
Regex for Canadian Postal Code — Pattern Explained with Examples

Regex for Canadian Postal Code — Pattern Explained with Examples

DodaTech Updated Jun 20, 2026 2 min read

Canadian postal codes are six-character alphanumeric codes in an alternating letter-digit pattern separated by a space. This pattern validates the standard A#A #A# format used by Canada Post for mail sorting and delivery.

The Pattern

/^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i

Pattern Breakdown

PartMeaning
^Start-of-string anchor
[A-Z]\d[A-Z]Letter-digit-letter (FSA — forward sortation area)
\s?Optional whitespace separator
\d[A-Z]\dDigit-letter-digit (LDU — local delivery unit)
$End-of-string anchor
iCase-insensitive flag

Matches

  • K1A 0B1
  • H0H 0H0
  • V6B 4Y8
  • M5V 2T6
  • T2P 1J9

Does NOT Match

  • K1A0B1 (no space)
  • 12345
  • K1A 0B
  • ABCD
  • A1A1A1A1
  • K1A-0B1

Language Examples

JavaScript

const caPostalRegex = /^[A-Z]\d[A-Z]\s?\d[A-Z]\d$/i;
console.log(caPostalRegex.test('K1A 0B1')); // true
console.log(caPostalRegex.test('12345'));    // false

Python

import re
pattern = r'^[A-Z]\d[A-Z]\s?\d[A-Z]\d$'
print(bool(re.match(pattern, 'K1A 0B1', re.IGNORECASE))) # True
print(bool(re.match(pattern, '12345', re.IGNORECASE)))    # False

Common Pitfalls

  • The first letter denotes a province or region (K for Ontario, V for British Columbia, etc.) — some letters like D, F, I, O, Q, and U are not used in the first position by Canada Post
  • The space is technically optional but strongly recommended — Canada Post formatting standards include it
  • Input should be reformatted to uppercase for consistency, even though the pattern is case-insensitive
  • The letters D, F, I, O, Q, and U do not appear in Canadian postal codes at all due to optical character recognition issues
  • A valid format does not guarantee a real postal code — the code must exist in the Canada Post database for delivery

Real-World Use Cases

  • Canadian e-commerce platforms — validate shipping addresses for orders within Canada
  • Address autocomplete services — validate partial postal code input before suggesting addresses
  • Mailing list hygiene — clean and standardize postal codes in customer databases before bulk mailings

FAQ

Is the space in a Canadian postal code required?
Canada Post recommends leaving a single space between the FSA and LDU (e.g., K1A 0B1). Most addressing software expects the space, but databases sometimes store codes without it. This pattern uses \s? to handle both cases.
What letters are never used in Canadian postal codes?
The letters D, F, I, O, Q, and U are never used in Canadian postal codes to avoid confusion with similar-looking numbers (0, 1) and letters. The letters W and Z are used only in specific circumstances.

Related Patterns

Regex for UK Postcode Regex for ZIP/Postal Code

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro