zipCode
Validates a postal/ZIP code for a specified country.
Options
| Option | Type | Default | Description |
|---|---|---|---|
country | string | undefined | ISO 3166-1 alpha-2 country code |
message | string | locale default | Custom error message |
Playground
Valid values by country (examples)
| Country | Value | Notes |
|---|---|---|
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
| Value | Country | Reason |
|---|---|---|
"AAAAA" | DE | Not digits |
"1234" | US | Only 4 digits instead of 5 |
Notes
- Empty string (
"") always returnsvalid: true. Combine withnotEmptyto require a value. - Without
country, returnsvalid: truefor 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.