开发者

Regular expression to match Amsterdam postcodes

开发者 https://www.devze.com 2022-12-25 13:21 出处:网络
can any one tell me regular expression for postalcode of Amsterdam, Netherlands for validation EX. 1113 GJ

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


^(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.


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

1[0-1][0-9]{2} [A-Z]{2}


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消