Regular Expressions 101

Community Patterns

Canadian Zip code - Optional space or hyphen seperator

1

Regular Expression
PCRE (PHP <7.3)

/
^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ][ -]?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$
/

Description

Match a string that's completely made up of a Canadian Zip code that can contain a space or hyphen as a seperator.

Submitted by Mike Bald - 8 years ago