ZIP Codes & Postal Codes Explained: Formats in 40 Countries
Postal codes look like simple numbers until your form rejects a perfectly valid Canadian or British one. This guide explains how postal codes are structured around the world and how to generate valid-format codes to test your validation.
How postal codes are structured
- United States: five digits; the first digit is a regional zone (0 = New England, 9 = West Coast).
- United Kingdom: an outward code (area + district, e.g.
SW1A) and an inward code (2AA). - Canada: letter-digit-letter digit-letter-digit; the first letter identifies the province.
- Netherlands: four digits and two letters (
1016 GV). - Brazil: eight-digit CEP written
00000-000. - Japan: seven digits as
123-4567. - UAE: no postcodes — P.O. Boxes instead.
Validation mistakes we see most often
- Digits-only regexes that reject UK, Canadian and Dutch codes.
- Removing the space that UK and Canadian codes need.
- Fixed five-character limits that cut Brazilian or Japanese codes.
- Making postcode mandatory for countries without one.
The safest approach is per-country validation — and testing it with codes from many countries at once.
Generate valid-format codes for testing
The ZIP code generator produces codes matched to a real city and using that city’s regional prefix. Generate 100 at a time, export CSV and run them through your validator. Every code should pass format checks; if one fails, you’ve found a bug before your customers did.
Pro tips
- Store postal codes as text, never as integers — leading zeros matter (e.g. 02108 Boston).
- Normalise case and spacing on input, but display codes in the official format.
- Use the Random Address Generator when you need full addresses rather than codes alone.