Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Canadian Postal Codes

Canadian postal codes contain six characters made up of alternating characters and digits. The first series of three characters and digits identifies the forward sortation area (or FSA), and the second series of three characters and digits identifies the local delivery unit (or LDU). The first character of the FSA identifies the province, territory, or region (18 characters are valid in this position, A for Newfoundland and Labrador, B for Nova Scotia, K, L, N and P for Ontario, excluding Toronto, which uses M, and so on), and so validation should ideally check to ensure that the first character is a valid one. Canadian postal codes are generally formatted using a space to separate the FSA from the LDU.

123 4th Street, Toronto, Ontario, M1A 1A1
567 8th Avenue, Montreal, Quebec, H9Z 9Z9
[ABCEGHJKLMNPRSTVXY]\ d[A-Z] \ d[A-Z]\ d
123 4th Street, Toronto, Ontario, M1A 1A1
567 8th Avenue, Montreal, Quebec, H9Z 9Z9

[ABCEGHJKLMNPRSTVXY] matches any one of those 18 valid characters, and \ d[A-Z] matches a digit followed by any alphabetic character, and thus the FSA. \ d[A-Z]\ d matches the LDU, a digit followed by an alphabetic character followed by a digit.

  • + Share This
  • 🔖 Save To Your Account