100% Client-Side β’ 0 B Data Leaves Browser
validation
Canada Postal Code Regex
Validates Canadian postal codes adhering to official Canada Post character exclusions (excludes D, F, I, O, Q, U).
Regular Expression Pattern:
/^[A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z] ?\d[A-CEGHJ-NPR-TV-Z]\d$/i
Valid Match Example:
K1A 0B1
Invalid / Non-Match Example:
D1A 0B1
Regex Syntax Breakdown & Explanation
- β’^[A-CEGHJ-NPR-TVXY] : First letter denotes geographic province (excludes disallowed letters)
- β’\d[A-Z] : Alternating number and letter structure
- β’? : Optional space separating Forward Sortation Area from Local Delivery Unit
Implementation in Popular Languages
JavaScript / TypeScript
const regex = /^[A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z] ?\d[A-CEGHJ-NPR-TV-Z]\d$/i;
const isValid = regex.test("K1A 0B1");
console.log(isValid); // truePython (re)
import re pattern = r"^[A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z] ?\d[A-CEGHJ-NPR-TV-Z]\d$" match = re.match(pattern, "K1A 0B1") print(bool(match)) # True
Go (regexp)
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z] ?\d[A-CEGHJ-NPR-TV-Z]\d$`)
fmt.Println(re.MatchString("K1A 0B1"))
}Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
The regular expression pattern is /^[A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z] ?\d[A-CEGHJ-NPR-TV-Z]\d$/i. Validates Canadian postal codes adhering to official Canada Post character exclusions (excludes D, F, I, O, Q, U).