views:

101

answers:

3

can any one tell me regular expression for postalcode of Amsterdam, Netherlands for validation EX. 1113 GJ

Postal code format according to Wikipedia (thanks to Pekka):

1011–1199 plus a literal suffix AA-ZZ, e.g. 1012 PP

A: 

Edit after the Wikipedia definition was posted (nice one Pekka :) ):

1[0-1][0-9]{2} [A-Z]{2}
Daniel
Matches some illegal numbers (like 1000).
Tim Pietzcker
Well spotted :) .
Daniel
A: 

Try:

^(11[0-9]{2}|10[1-9]{2}|10[2-9]0)\s*([A-Z]{2}|[a-z]{2})

As the postalcode range of Amsterdam is from 1011, using 1[0-1][0-9]{2} will also cause the 1000 code to match. In this example the range 1000 - 1010 will not be matched.

This bit matches 1100 - 1199:

(^11[0-9]{2})

This bit matches 1011 - 1099, but does not match 1020, 1030, 1040 and so on:

(^10[1-9]{2})

This bit matches 1020 - 1090, in steps of 10, matching 1020,1030,1040 and so on:

(^10[2-9]0)
lugte098
i dont get why i got a -1 :S
lugte098
+5  A: 
^(11[0-9]{2}|10[2-9][0-9]|101[1-9])\s*[A-Z]{2}$

will match numbers from 1011-1199, followed by two letters from A to Z.

Tim Pietzcker