Postal code regex for UK Crown Dependencies

122 views
Skip to first unread message

M Goren

unread,
Dec 8, 2020, 4:09:54 PM12/8/20
to GeoNames
Hi,
I was implementing postcode verification using the data in http://download.geonames.org/export/dump/countryInfo.txt and tests started failing for Isle of Man, Guernsey and Jersey.
Apparently, the regular expression specified for these 3 territories (it is the same regex, repeated 3 times) is incorrect. In fact, it is not possible to match postcodes defined by the UK post office using this regex!
The correct ones are supposed to be:
for Isle of Man, ^(IM(?:[1-9]|86|87|99)\s[0-9][A-Z]{2})$ with format IM# #@@|IM## #@@
for Guernsey, ^(GY(?:[1-9]|10)\s[0-9][A-Z]{2})$ with format GY# #@@|GY10 #@@
for Jersey, ^(JE[1-5]\s[0-9][A-Z]{2})$ with format JE# #@@

Best,
M.
Reply all
Reply to author
Forward
0 new messages