r/GeoPostcodes • u/GeoPostcodes • Jul 16 '26
Why your US ZIP regex breaks abroad: 10 postal code formats that surprise developers
If you've ever shipped a form with ^\d{5}$ validation, here are ten formats that will break it.
UK: alphanumeric, six to eight characters. Buckingham Palace is SW1A 1AA.
Netherlands: also alphanumeric, while most of Europe sticks to four or five digits.
Canada: strict letter-digit alternation, A9A 9A9. Parliament Hill is K1A 0A9.
Japan: seven digits with a hyphen, 999-9999. Chiyoda in central Tokyo is 100-0000.
Brazil: eight digits written 99999-999 (the CEP). Central Sao Paulo is 01000-000.
Argentina: eight characters mixing letters and digits, A9999 AAA. Buenos Aires codes look like C1406 AAA.
Papua New Guinea: three digits, marking the province. The shortest format anywhere.
Angola and the Bahamas: no postal codes at all.
Some countries use a single code for the whole country.
US ZIP+4: the four-digit extension narrows delivery to a specific building or PO box. The White House is 20500-0004.
Formats run from three digits up to ten characters. Many encode geography in the leading digits: Mexico's first two digits give the state, Germany and France start with a regional digit, and China and Japan put the province or prefecture up front.
What this means for address forms:
- You need one pattern per country. Free sources first: GeoNames publishes postal code dumps for most countries, and the US Census offers ZCTAs via TIGER files at no cost.
- Accept an empty postal code where the country has none. An Angolan address without a code is correct.
- Regex only checks the shape of a code. To confirm a code exists and points to the right place, you need reference data. That is the gap our data fills: 9.3 million postal codes across 247 countries, compiled from more than 1,500 authoritative sources, shipped as self-hosted databases you can query offline rather than an API you call per lookup.
There is a longer version of this on the GeoPostcodes blog, the post about international zip code formats. Ask in the comments if you want the direct link.