7.1

Table Of Contents
11.2 Examples
The following examples may be useful.
Only numbers
The following regular expression accepts only numbers as input.
[0-9]+
The expression step by step:
[0-9] Numbers 0 through 9
+ one or multiple
Dutch zip code
The Dutch zip code consists of four numbers, one space and two uppercase letters (eg 1234 AB).
[0-9]{4}\s[A-Z]{2}
The expression step by step:
[0-9]{4} Four numbers
\s a single space ("" or [] or \s)
[A-Z]{2} Two uppercase characters
Canadian zip codes
Canadian postal codes alternate between letter and number such as L0S 1E0. Some choose not to put in the
space. And not every letter is used as the first letter which designates region. The regions are (from east to
west, then north): A,B,C,E,G,H,J,K,L,M,N,P,R,S,T,V,X,Y.
\s*[a-ceghj-npr-tvxyA-CEGHJ-NPR-TVXY]\d[a-zA-Z](\s)?\d[a-zA-Z]\d\s*
The expression step by step:
\s* Zero or more whitespaces
[a-ceghj-npr-tvxyA-CEGHJ-NPR-TVXY] The regions letters
\d One digit
[a-zA-Z] One letter
(\s)? Zero or one whitespace
\d One digit
[a-zA-Z] One letter
\d One digit
\s* Zero or more whitespaces
Objectif Lune Inc. © 2010 155