Skip to content

zipCode

Validates a postal/ZIP code for a specified country.

Options

OptionTypeDefaultDescription
countrystringundefinedISO 3166-1 alpha-2 country code
messagestringlocale defaultCustom error message

Playground

Valid values by country (examples)

CountryValueNotes
US"10001"New York ZIP code
DE"10115"Berlin postal code
GB"SW1A 1AA"London postal code
CA"K1A 0A9"Ottawa postal code

Invalid values

ValueCountryReason
"AAAAA"DENot digits
"1234"USOnly 4 digits instead of 5

Notes

  • Empty string ("") always returns valid: true. Combine with notEmpty to require a value.
  • Without country, returns valid: true for any value (pass-through).
  • Supported countries: AT, BG, BR, CA, CH, CZ, DE, DK, ES, FR, GB, IE, IN, IT, MA, NL, PL, PT, RO, RU, SE, SG, SK, US.

Released under the MIT License.