Reference · Parsing, formatting and shared types
CANADIAN_POSTAL_CODE_PATTERNconstant
A Canadian postal code with the letters Canada Post assigns, with or without its space.
Import it
import { CANADIAN_POSTAL_CODE_PATTERN } from "@johnmorrisdotca/address-plus";
Definition
const CANADIAN_POSTAL_CODE_PATTERN: RegExp = /^([A-Z]\d[A-Z])[-\s]*(\d[A-Z]\d)$/i
Examples
import { CANADIAN_POSTAL_CODE_PATTERN } from "@johnmorrisdotca/address-plus";
console.log(CANADIAN_POSTAL_CODE_PATTERN.test("M5H 2N2"));
// → truetrueWhat it prints (run when this page was built)