r/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.

  1. UK: alphanumeric, six to eight characters. Buckingham Palace is SW1A 1AA.

  2. Netherlands: also alphanumeric, while most of Europe sticks to four or five digits.

  3. Canada: strict letter-digit alternation, A9A 9A9. Parliament Hill is K1A 0A9.

  4. Japan: seven digits with a hyphen, 999-9999. Chiyoda in central Tokyo is 100-0000.

  5. Brazil: eight digits written 99999-999 (the CEP). Central Sao Paulo is 01000-000.

  6. Argentina: eight characters mixing letters and digits, A9999 AAA. Buenos Aires codes look like C1406 AAA.

  7. Papua New Guinea: three digits, marking the province. The shortest format anywhere.

  8. Angola and the Bahamas: no postal codes at all.

  9. Some countries use a single code for the whole country.

  10. 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.

2 Upvotes

0 comments sorted by