EN
My tools

ZIP Code Regex (Postal Code Patterns by Country)

Copy a tested postal code regex for the US (ZIP+4), Canada, the UK, Germany, Japan, Korea, India and 30 more countries, or find which country a code fits.

Regex
/^[0-9]{5}(?:[ -][0-9]{4})?$/i
United States · example 90210-1234
Code
const ok = /^[0-9]{5}(?:[ -][0-9]{4})?$/i.test(value.trim());
Matches
3
No match
3

ZIP or ZIP+4 (USPS); the +4 is separated by a hyphen (a space is also accepted).

A match only means the code is well-formed. Whether it exists needs the postal operator's database.

Test results — United States
LineCodeResultReason
190210Match
290210-1234Match
39021No matchFits Australia, Switzerland, Austria, Belgium instead
490210 1234Match
512345-123No matchFits Brazil instead
6SW1A 1AANo matchFits United Kingdom instead
My tools →
Advertisement

Postal codes differ completely between countries: five digits in the US (or ZIP+4), letter-digit-letter in Canada, the irregular outward/inward codes of the UK, 4 digits plus 2 letters in the Netherlands, five digits in Korea since 2015. This tool gives a tested regex for each of 35 formats with code for JavaScript, PHP, Python, Java, C# or an HTML pattern attribute, checks a list of codes, and can tell you which countries a code fits.

How to use this tool

  1. Choose the country (or "All" to identify a code).
  2. Choose the language and whether lower-case letters are accepted.
  3. Paste the codes to check, one per line.
  4. Copy the regex or the code snippet.

Formula

US: [0-9]{5}(?:[ -][0-9]{4})? · Canada: [A-Z][0-9][A-Z] ?[0-9][A-Z][0-9] (restricted letters) · UK: outward code ?[0-9][A-Z]{2}

Patterns follow the formats published by the postal operators and Google's address metadata (libaddressinput), including letter restrictions where they are documented — Canada never uses D, F, I, O, Q or U, Dutch codes never end in SA, SD or SS, Spanish codes start with a province number 01–52, Indian PINs never start with 0. Values are trimmed; inner spaces must be single. A pattern checks the format only: 99999 is a well-formed US ZIP that does not exist.

Example

For the United States the sample gives 3 matches: 90210, 90210-1234 and 90210 1234. 9021 has only four digits, 12345-123 has a three-digit extension, and SW1A 1AA is a British postcode — the tester says so. Switched to the UK, SW1A 1AA, W1A 0AX and DN55 1PT all match, while SW1A 1A is incomplete.

Frequently asked questions

Should I validate postal codes at all?

Only loosely, and only when you know the country. A strict pattern for the wrong country rejects real customers; many shops accept any text and check it with the carrier instead.

Why is the UK pattern so long?

UK postcodes have six shapes of outward code (A9, A99, AA9, AA99, A9A, AA9A) followed by a digit and two letters. The pattern lists them and excludes letters that are not used in certain positions.

What changed in Korea in 2015?

Korea Post replaced the six-digit code (e.g. 110-760) with five-digit area codes on 1 August 2015. Both patterns are available here.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). ZIP Code Regex (Postal Code Patterns by Country). https://kakao.mobile/tools/zip-code-regex-tool/

MLA

“ZIP Code Regex (Postal Code Patterns by Country).” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/zip-code-regex-tool/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement