Last active
June 6, 2024 14:19
-
-
Save ShreyKumar/43ebb040383c90ed976439245423aa38 to your computer and use it in GitHub Desktop.
List of countries and their respective postal codes with ranges (August 2020)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Country list source: https://www.dhl.com/en/country_profile.html#.XwODEJNKjOQ | |
// Country abbreviation source: https://planetarynames.wr.usgs.gov/Abbreviations | |
// Postal code: https://gist.githubusercontent.com/jamesbar2/1c677c22df8f21e869cca7e439fc3f5b/raw/21662445653ac861f8ab81caa8cfaee3185aed15/postal-codes.json | |
// Postal code: https://en.wikipedia.org/wiki/List_of_postal_codes | |
// Country/territory items with no postal code regexes or ranges either do not require postal codes | |
// or there may not be enough information for that country/territory | |
export const COUNTRY_ADDRESS_POSTALS = [{ | |
abbrev: 'AF', | |
name: 'Afghanistan', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'AL', | |
name: 'Albania', | |
postal: /(120|122)[0-9]{2}/g, | |
}, { | |
abbrev: 'DZ', | |
name: 'Algeria', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'AS', | |
name: 'American Samoa', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'AD', | |
name: 'Andorra', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'AO', | |
name: 'Angola', | |
}, { | |
abbrev: 'AI', | |
name: 'Anguilla', | |
postal: /AI-2640/g, | |
}, { | |
abbrev: 'AG', | |
name: 'Antigua and Barbuda', | |
}, { | |
abbrev: 'AR', | |
name: 'Argentina', | |
postal: /[A-Z]{1}[0-9]{4}[A-Z]{3}/g, | |
}, { | |
abbrev: 'AM', | |
name: 'Armenia', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'AW', | |
name: 'Aruba', | |
}, { | |
abbrev: 'AU', | |
name: 'Australia', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'AT', | |
name: 'Austria', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'AZ', | |
name: 'Azerbaijan', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'BS', | |
name: 'Bahamas', | |
}, { | |
abbrev: 'BH', | |
name: 'Bahrain', | |
}, { | |
abbrev: 'BD', | |
name: 'Bangladesh', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'BB', | |
name: 'Barbados', | |
postal: /BB[0-9]{5}/g, | |
}, { | |
abbrev: 'BY', | |
name: 'Belarus', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'BE', | |
name: 'Belgium', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'BZ', | |
name: 'Belize', | |
}, { | |
abbrev: 'BJ', | |
name: 'Benin', | |
}, { | |
abbrev: 'BM', | |
name: 'Bermuda', | |
postal: /[A-Z]{2}[0-9]{2}/g, | |
}, { | |
abbrev: 'BT', | |
name: 'Bhutan', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'BO', | |
name: 'Bolivia', | |
}, { | |
abbrev: 'BQ', | |
name: 'Bonaire', | |
}, { | |
abbrev: 'BA', | |
name: 'Bosnia and Herzegovina', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'BW', | |
name: 'Botswana', | |
}, { | |
abbrev: 'BR', | |
name: 'Brazil', | |
postal: /[0-9]{5}-[0-9]{3}/g, | |
}, { | |
abbrev: 'BN', | |
name: 'Brunei', | |
postal: /[A-Z]{2}[0-9]{4}/g, | |
}, { | |
abbrev: 'BG', | |
name: 'Bulgaria', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'BF', | |
name: 'Burkina Faso', | |
}, { | |
abbrev: 'BI', | |
name: 'Burundi', | |
}, { | |
abbrev: 'KH', | |
name: 'Cambodia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CM', | |
name: 'Cameroon', | |
}, { | |
abbrev: 'CA', | |
name: 'Canada', | |
postal: /[A-Z][0-9][A-Z] ?[0-9][A-Z][0-9]/g, | |
}, { | |
abbrev: 'CI', | |
name: 'Canary Islands', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CV', | |
name: 'Cape Verde', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'KY', | |
name: 'Cayman Islands', | |
postal: /[A-Z]{2}[0-9]-[0-9]{4}/g, | |
}, { | |
abbrev: 'CF', | |
name: 'Central African Republic', | |
}, { | |
abbrev: 'TD', | |
name: 'Chad', | |
}, { | |
abbrev: 'CI', | |
name: 'Channel Islands', | |
postal: /[A-Z]{2}[0-9]{2}/g, | |
}, { | |
abbrev: 'CL', | |
name: 'Chile', | |
postal: /[0-9]{7}/g, | |
}, { | |
abbrev: 'CN', | |
name: "China, People's Republic", | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CO', | |
name: 'Colombia', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'KM', | |
name: 'Comoros', | |
}, { | |
abbrev: 'CG', | |
name: 'Congo', | |
}, { | |
abbrev: 'CD', | |
name: 'Congo, The Democratic Republic of', | |
}, { | |
abbrev: 'CK', | |
name: 'Cook Islands', | |
}, { | |
abbrev: 'CR', | |
name: 'Costa Rica', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CI', | |
name: "Côte d'Ivoire", | |
}, { | |
abbrev: 'HR', | |
name: 'Croatia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CU', | |
name: 'Cuba', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CW', | |
name: 'Curacao', | |
}, { | |
abbrev: 'CY', | |
name: 'Cyprus', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'CZ', | |
name: 'Czech Republic', | |
postal: /[0-9]{3} [0-9]{2}/g, | |
}, { | |
abbrev: 'DK', | |
name: 'Denmark', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'DJ', | |
name: 'Djibouti', | |
}, { | |
abbrev: 'DM', | |
name: 'Dominica', | |
}, { | |
abbrev: 'DO', | |
name: 'Dominican Republic', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'TL', | |
name: 'East Timor', | |
}, { | |
abbrev: 'EC', | |
name: 'Ecuador', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'EG', | |
name: 'Egypt', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'SV', | |
name: 'El Salvador', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'ER', | |
name: 'Eritrea', | |
}, { | |
abbrev: 'EE', | |
name: 'Estonia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'ET', | |
name: 'Ethiopia', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'FK', | |
name: 'Falkland Islands', | |
postal: /FIQQ 1ZZ/g, | |
}, { | |
abbrev: 'FO', | |
name: 'Faroe Islands', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'FJ', | |
name: 'Fiji', | |
}, { | |
abbrev: 'FI', | |
name: 'Finland', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'FR', | |
name: 'France', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'PF', | |
name: 'French Polynesia', | |
postal: /987[0-9]{2}/g, | |
range: ['98700', '98790'], | |
}, { | |
abbrev: 'GA', | |
name: 'Gabon', | |
}, { | |
abbrev: 'GM', | |
name: 'Gambia', | |
}, { | |
abbrev: 'GE', | |
name: 'Georgia', | |
}, { | |
abbrev: 'DE', | |
name: 'Germany', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'GH', | |
name: 'Ghana', | |
}, { | |
abbrev: 'GI', | |
name: 'Gibraltar', | |
postal: /GX11 1AA/g, | |
}, { | |
abbrev: 'GR', | |
name: 'Greece', | |
postal: /[0-9]{3} [0-9]{2}/g, | |
}, { | |
abbrev: 'GL', | |
name: 'Greenland', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'GD', | |
name: 'Grenada', | |
}, { | |
abbrev: 'GP', | |
name: 'Guadeloupe', | |
postal: /971[0-9]{2}/g, | |
range: ['97100', '97190'], | |
}, { | |
abbrev: 'GU', | |
name: 'Guam', | |
// US postal code | |
// https://stackoverflow.com/questions/2577236/regex-for-zip-code | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
range: ['96910', '96932'], | |
}, { | |
abbrev: 'GT', | |
name: 'Guatemala', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'GG', | |
name: 'Guernsey', | |
// UK postal code | |
// https://stackoverflow.com/questions/164979/regex-for-matching-uk-postcodes | |
postal: /([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\s?[0-9][A-Za-z]{2})/g, | |
}, { | |
abbrev: 'GW', | |
name: 'Guinea-Bissau', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'GQ', | |
name: 'Guinea-Equatorial', | |
}, { | |
abbrev: 'GN', | |
name: 'Guinea Republic', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'GY', | |
name: 'Guyana (British)', | |
}, { | |
abbrev: 'GF', | |
name: 'Guyana (French)', | |
postal: /973[0-9]{2}/g, | |
range: ['97300', '97390'], | |
}, { | |
abbrev: 'HT', | |
name: 'Haiti', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'HN', | |
name: 'Honduras', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'HK', | |
name: 'Hong Kong', | |
}, { | |
abbrev: 'HU', | |
name: 'Hungary', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'IS', | |
name: 'Iceland', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'IN', | |
name: 'India', | |
// https://stackoverflow.com/questions/33865525/indian-pincode-validation-regex-only-six-digits-shouldnt-start-with-0 | |
postal: /^[1-9][0-9]{5}$/g, | |
}, { | |
abbrev: 'ID', | |
name: 'Indonesia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'IR', | |
name: 'Iran', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'IQ', | |
name: 'Iraq', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'IE', | |
name: 'Ireland, Republic of', | |
// https://stackoverflow.com/questions/33391412/validation-for-irish-eircode | |
postal: /(?:^[AC-FHKNPRTV-Y][0-9]{2}|D6W)[ -]?[0-9AC-FHKNPRTV-Y]{4}$/g, | |
}, { | |
abbrev: 'FK', | |
name: 'Islas Malvinas', | |
postal: /FIQQ 1ZZ/g, | |
}, { | |
abbrev: 'IL', | |
name: 'Israel', | |
postal: /[0-9]{5}|[0-9]{7}/g, | |
}, { | |
abbrev: 'IT', | |
name: 'Italy', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'CI', | |
name: 'Ivory Coast', | |
}, { | |
abbrev: 'JM', | |
name: 'Jamaica', | |
}, { | |
abbrev: 'JP', | |
name: 'Japan', | |
postal: /[0-9]{3}-[0-9]{4}/g, | |
}, { | |
abbrev: 'JE', | |
name: 'Jersey', | |
postal: /([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\s?[0-9][A-Za-z]{2})/g, | |
}, { | |
abbrev: 'JO', | |
name: 'Jordan', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'KZ', | |
name: 'Kazakhstan', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'KE', | |
name: 'Kenya', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'KI', | |
name: 'Kiribati', | |
}, { | |
abbrev: 'KR', | |
name: 'Korea, Republic of', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'KP', | |
name: 'Korea, The D.P.R of', | |
}, { | |
abbrev: 'XK', | |
name: 'Kosovo', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'KW', | |
name: 'Kuwait', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'KG', | |
name: 'Kyrgyzstan', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'LA', | |
name: 'Laos', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'LV', | |
name: 'Latvia', | |
postal: /LV-[0-9]{4}/g, | |
}, { | |
abbrev: 'LB', | |
name: 'Lebanon', | |
postal: /[0-9]{4} [0-9]{4}/g, | |
}, { | |
abbrev: 'LS', | |
name: 'Lesotho', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'LR', | |
name: 'Liberia', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'LY', | |
name: 'Libya', | |
}, { | |
abbrev: 'LI', | |
name: 'Liechtenstein', | |
postal: /[0-9]{4}/g, | |
range: ['9485', '9498'], | |
}, { | |
abbrev: 'LT', | |
name: 'Lithuania', | |
postal: /LT-[0-9]{5}/g, | |
}, { | |
abbrev: 'LU', | |
name: 'Luxembourg', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'MO', | |
name: 'Macau', | |
}, { | |
abbrev: 'MK', | |
name: 'Macedonia, Republic of', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'MG', | |
name: 'Madagascar', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'MW', | |
name: 'Malawi', | |
}, { | |
abbrev: 'MY', | |
name: 'Malaysia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'MV', | |
name: 'Maldives', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'ML', | |
name: 'Mali', | |
}, { | |
abbrev: 'MT', | |
name: 'Malta', | |
postal: /[A-Z]{3} [0-9]{4}/g, | |
}, { | |
abbrev: 'MH', | |
name: 'Marshall Islands', | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
range: ['96960', '96970'], | |
}, { | |
abbrev: 'MQ', | |
name: 'Martinique', | |
postal: /972[0-9]{2}/g, | |
range: ['97200', '97290'], | |
}, { | |
abbrev: 'MR', | |
name: 'Mauritania', | |
}, { | |
abbrev: 'MU', | |
name: 'Mauritius', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'YT', | |
name: 'Mayotte', | |
postal: /976[0-9]{2}/g, | |
range: ['97600', '97690'], | |
}, { | |
abbrev: 'MX', | |
name: 'Mexico', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'MD', | |
name: 'Moldova, Republic of', | |
postal: /MD-?[0-9]{4}/g, | |
}, { | |
abbrev: 'MC', | |
name: 'Monaco', | |
postal: /980[0-9]{2}/g, | |
}, { | |
abbrev: 'MN', | |
name: 'Mongolia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'ME', | |
name: 'Montenegro', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'MS', | |
name: 'Montserrat', | |
postal: /MSR [0-9]{4}/g, | |
range: ['MSR 1110', 'MSR 1350'], | |
}, { | |
abbrev: 'MA', | |
name: 'Morocco', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'MZ', | |
name: 'Mozambique', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'MM', | |
name: 'Myanmar', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'NA', | |
name: 'Namibia', | |
}, { | |
abbrev: 'NR', | |
name: 'Nauru', | |
}, { | |
abbrev: 'NP', | |
name: 'Nepal', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'NL', | |
name: 'Netherlands', | |
// https://rgxdb.com/r/4W9GV8AC | |
postal: /^(?:NL-)?(\d{4})\s*([A-Z]{2})$/i, | |
}, { | |
abbrev: 'NC', | |
name: 'New Caledonia', | |
postal: /988[0-9]{2}/g, | |
range: ['96950', '96952'], | |
}, { | |
abbrev: 'NZ', | |
name: 'New Zealand', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'NI', | |
name: 'Nicaragua', | |
}, { | |
abbrev: 'NE', | |
name: 'Niger', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'NG', | |
name: 'Nigeria', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'NU', | |
name: 'Niue', | |
}, { | |
abbrev: 'MP', | |
name: 'Northern Mariana Islands', | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
}, { | |
abbrev: 'NO', | |
name: 'Norway', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'OM', | |
name: 'Oman', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'PK', | |
name: 'Pakistan', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'PW', | |
name: 'Palau', | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
}, { | |
abbrev: 'PA', | |
name: 'Panama', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'PG', | |
name: 'Papua New Guinea', | |
postal: /[0-9]{3}/g, | |
}, { | |
abbrev: 'PY', | |
name: 'Paraguay', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'PE', | |
name: 'Peru', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'PH', | |
name: 'Philippines', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'PL', | |
name: 'Poland', | |
postal: /[0-9]{2}-[0-9]{3}/g, | |
}, { | |
abbrev: 'PT', | |
name: 'Portugal', | |
postal: /[0-9]{4}-[0-9]{3}/g, | |
}, { | |
abbrev: 'PR', | |
name: 'Puerto Rico', | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
}, { | |
abbrev: 'QA', | |
name: 'Qatar', | |
}, { | |
abbrev: 'RE', | |
name: 'Réunion', | |
postal: /974[0-9]{2}/g, | |
range: ['97400', '97490'], | |
}, { | |
abbrev: 'RO', | |
name: 'Romania', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'RU', | |
name: 'Russian Federation', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'RW', | |
name: 'Rwanda', | |
}, { | |
abbrev: 'MP', | |
name: 'Saipan', | |
postal: /96950/g, | |
}, { | |
abbrev: 'WS', | |
name: 'Samoa', | |
postal: /WS[0-9]{4}/g, | |
}, { | |
abbrev: 'ST', | |
name: 'Sao Tome and Principe', | |
}, { | |
abbrev: 'SA', | |
name: 'Saudi Arabia', | |
postal: /[0-9]{5}(-[0-9]{4})?/g, | |
}, { | |
abbrev: 'SN', | |
name: 'Senegal', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'RS', | |
name: 'Serbia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'SC', | |
name: 'Seychelles', | |
}, { | |
abbrev: 'SL', | |
name: 'Sierra Leone', | |
}, { | |
abbrev: 'SG', | |
name: 'Singapore', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'SK', | |
name: 'Slovakia', | |
postal: /[0-9]{3} [0-9]{2}/g, | |
}, { | |
abbrev: 'SI', | |
name: 'Slovenia', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'SB', | |
name: 'Solomon Islands', | |
}, { | |
abbrev: 'SO', | |
name: 'Somalia', | |
postal: /[A-Z]{2} [0-9]{5}/g, | |
}, { | |
abbrev: 'ZA', | |
name: 'South Africa', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'SS', | |
name: 'South Sudan', | |
}, { | |
abbrev: 'ES', | |
name: 'Spain', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'LK', | |
name: 'Sri Lanka', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'BL', | |
name: 'St. Barthélemy', | |
postal: /[0-9]{5}/g, | |
range: ['97100', '97190'], | |
}, { | |
abbrev: 'VI', | |
name: 'St. Croix', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'SE', | |
name: 'St. Eustatius', | |
}, { | |
abbrev: 'SH', | |
name: 'St. Helena', | |
postal: /STHL 1ZZ/g, | |
}, { | |
abbrev: 'AG', | |
name: 'St. John', | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
}, { | |
abbrev: 'KN', | |
name: 'St. Kitts and Nevis', | |
postal: /[A-Z]{2}[0-9]{4}/g, | |
}, { | |
abbrev: 'LC', | |
name: 'St. Lucia', | |
postal: /[A-Z]{2}[0-9]{2} [0-9]{3}/g, | |
}, { | |
abbrev: 'SX', | |
name: 'St. Maarten', | |
}, { | |
abbrev: 'VI', | |
name: 'St. Thomas', | |
}, { | |
abbrev: 'VC', | |
name: 'St. Vincent and the Grenadines', | |
postal: /VC[0-9]{4}/g, | |
}, { | |
abbrev: 'SD', | |
name: 'Sudan', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'SR', | |
name: 'Suriname', | |
}, { | |
abbrev: 'SZ', | |
name: 'Swaziland', | |
postal: /[A-Z]{1}[0-9]{3}/g, | |
}, { | |
abbrev: 'SE', | |
name: 'Sweden', | |
postal: /[0-9]{3} [0-9]{2}/g, | |
}, { | |
abbrev: 'CH', | |
name: 'Switzerland', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'SY', | |
name: 'Syria', | |
}, { | |
abbrev: 'PF', | |
name: 'Tahiti', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'TW', | |
name: 'Taiwan', | |
postal: /[0-9]{3}(-[0-9]{2})?/g, | |
}, { | |
abbrev: 'TZ', | |
name: 'Tanzania', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'TH', | |
name: 'Thailand', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'TG', | |
name: 'Togo', | |
}, { | |
abbrev: 'TO', | |
name: 'Tonga', | |
}, { | |
abbrev: 'VG', | |
name: 'Tortola', | |
postal: /VG[0-9]{4}/g, | |
}, { | |
abbrev: 'TT', | |
name: 'Trinidad and Tobago', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'TN', | |
name: 'Tunisia', | |
postal: /[0-9]{4}/g, | |
}, { | |
abbrev: 'TR', | |
name: 'Turkey', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'TM', | |
name: 'Turkmenistan', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'TC', | |
name: 'Turks and Caicos Islands', | |
postal: /TKCA 1ZZ/g, | |
}, { | |
abbrev: 'TV', | |
name: 'Tuvalu', | |
}, { | |
abbrev: 'UG', | |
name: 'Uganda', | |
}, { | |
abbrev: 'UA', | |
name: 'Ukraine', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'AE', | |
name: 'United Arab Emirates', | |
}, { | |
abbrev: 'GB', | |
name: 'United Kingdom', | |
postal: /([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\s?[0-9][A-Za-z]{2})/g, | |
}, { | |
abbrev: 'US', | |
name: 'United States of America', | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
}, { | |
abbrev: 'UY', | |
name: 'Uruguay', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'UZ', | |
name: 'Uzbekistan', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'VU', | |
name: 'Vanuatu', | |
}, { | |
abbrev: 'VE', | |
name: 'Venezuela', | |
postal: /[0-9]{4}(-[A-Z]{1})?/g, | |
}, { | |
abbrev: 'VN', | |
name: 'Vietnam', | |
postal: /[0-9]{6}/g, | |
}, { | |
abbrev: 'VG', | |
name: 'Virgin Islands (British)', | |
postal: /VG[0-9]{4}/g, | |
}, { | |
abbrev: 'VI', | |
name: 'Virgin Islands (US)', | |
range: ['00801', '00851'], | |
postal: /^\d{5}(?:[-\s]\d{4})?$/g, | |
}, { | |
abbrev: 'YE', | |
name: 'Yemen', | |
}, { | |
abbrev: 'ZM', | |
name: 'Zambia', | |
postal: /[0-9]{5}/g, | |
}, { | |
abbrev: 'ZW', | |
name: 'Zimbabwe', | |
}] |
Here I drop the php version with new match internal for 8+ versions:
$regex = match ($country_code) {
'AF' => "/[0-9]{4}/",
'AL' => "/(120|122)[0-9]{2}/",
'DZ' => '/[0-9]{5}/',
'AS' => '/[0-9]{5}/',
'AD' => '/[0-9]{5}/',
'AO' => '/^\d{5}$/',
'AI' => '/AI-2640/',
'AG' => '/\d{5}(?:[-\s]\d{4})?/',
'AR' => '/[A-Z]{1}[0-9]{4}[A-Z]{3}/',
'AM' => '/[0-9]{4}/',
'AW' => '/^\d{5}$/',
'AU' => '/[0-9]{4}/',
'AT' => '/[0-9]{4}/',
'AZ' => '/[0-9]{4}/',
'BS' => '/^\d{5}$/',
'BH' => '/^\d{5}$/',
'BD' => '/[0-9]{4}/',
'BB' => '/BB[0-9]{5}/',
'BY' => '/[0-9]{6}/',
'BE' => '/[0-9]{4}/',
'BZ' => '/^\d{5}$/',
'BJ' => '/^\d{5}$/',
'BM' => '/[A-Z]{2}[0-9]{2}/',
'BT' => '/[0-9]{5}/',
'BO' => '/^\d{5}$/',
'BQ' => '/^\d{5}$/',
'BA' => '/[0-9]{5}/',
'BW' => '/^\d{5}$/',
'BR' => '/[0-9]{5}-[0-9]{3}/',
'BN' => '/[A-Z]{2}[0-9]{4}/',
'BG' => '/[0-9]{4}/',
'BF' => '/^\d{5}$/',
'BI' => '/^\d{5}$/',
'KH' => '/[0-9]{5}/',
'CM' => '/^\d{5}$/',
'CA' => '/[A-Z][0-9][A-Z] ?[0-9][A-Z][0-9]/',
'CI' => '/^\d{5}$/',
'CV' => '/[0-9]{4}/',
'KY' => '/[A-Z]{2}[0-9]-[0-9]{4}/',
'CF' => '/^\d{5}$/',
'TD' => '/^\d{5}$/',
'CL' => '/[0-9]{7}/',
'CN' => '/[0-9]{6}/',
'CO' => '/[0-9]{6}/',
'KM' => '/^\d{5}$/',
'CG' => '/^\d{5}$/',
'CD' => '/^\d{5}$/',
'CK' => '/^\d{5}$/',
'CR' => '/[0-9]{5}/',
'HR' => '/[0-9]{5}/',
'CU' => '/[0-9]{5}/',
'CW' => '/^\d{5}$/',
'CY' => '/[0-9]{4}/',
'CZ' => '/[0-9]{3} [0-9]{2}/',
'DK' => '/[0-9]{5}/',
'DJ' => '/^\d{5}$/',
'DM' => '/^\d{5}$/',
'DO' => '/[0-9]{5}/',
'TL' => '/^\d{5}$/',
'EC' => '/[0-9]{6}/',
'EG' => '/[0-9]{5}/',
'SV' => '/[0-9]{4}/',
'ER' => '/^\d{5}$/',
'EE' => '/[0-9]{5}/',
'ET' => '/[0-9]{4}/',
'FK' => '/FIQQ 1ZZ/',
'FO' => '/[0-9]{3}/',
'FJ' => '/^\d{5}$/',
'FI' => '/[0-9]{5}/',
'FR' => '/[0-9]{5}/',
'PF' => '/[0-9]{5}/',
'GA' => '/^\d{5}$/',
'GM' => '/^\d{5}$/',
'GE' => '/^\d{5}$/',
'DE' => '/[0-9]{5}/',
'GH' => '/^\d{5}$/',
'GI' => '/GX11 1AA/',
'GR' => '/[0-9]{3} [0-9]{2}/',
'GL' => '/[0-9]{4}/',
'GD' => '/^\d{5}$/',
'GP' => '/971[0-9]{2}/',
'GU' => '/\d{5}(?:[-\s]\d{4})?/',
'GT' => '/[0-9]{5}/',
'GG' => '/([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\s?[0-9][A-Za-z]{2})/',
'GW' => '/[0-9]{4}/',
'GQ' => '/^\d{5}$/',
'GN' => '/[0-9]{3}/',
'GY' => '/^\d{5}$/',
'GF' => '/973[0-9]{2}/',
'HT' => '/[0-9]{4}/',
'HN' => '/[0-9]{5}/',
'HK' => '/^\d{5}$/',
'HU' => '/[0-9]{4}/',
'IS' => '/[0-9]{3}/',
'IN' => '/[1-9][0-9]{5}/',
'ID' => '/[0-9]{5}/',
'IR' => '/[0-9]{5}/',
'IQ' => '/[0-9]{5}/',
'IE' => '/(?:^[AC-FHKNPRTV-Y][0-9]{2}|D6W)[ -]?[0-9AC-FHKNPRTV-Y]{4}$/',
'IL' => '/[0-9]{5}|[0-9]{7}/',
'IT' => '/[0-9]{5}/',
'JM' => '/^\d{5}$/',
'JP' => '/[0-9]{3}-[0-9]{4}/',
'JE' => '/([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\s?[0-9][A-Za-z]{2})/',
'JO' => '/[0-9]{5}/',
'KZ' => '/[0-9]{6}/',
'KE' => '/[0-9]{5}/',
'KI' => '/^\d{5}$/',
'KR' => '/[0-9]{5}/',
'KP' => '/^\d{5}$/',
'XK' => '/[0-9]{5}/',
'KW' => '/[0-9]{5}/',
'KG' => '/[0-9]{6}/',
'LA' => '/[0-9]{5}/',
'LV' => '/LV-[0-9]{4}/',
'LB' => '/[0-9]{4} [0-9]{4}/',
'LS' => '/[0-9]{3}/',
'LR' => '/[0-9]{4}/',
'LY' => '/^\d{5}$/',
'LI' => '/[0-9]{4}/',
'LT' => '/LT-[0-9]{5}/',
'LU' => '/[0-9]{4}/',
'MO' => '/^\d{5}$/',
'MK' => '/[0-9]{4}/',
'MG' => '/[0-9]{3}/',
'MW' => '/^\d{5}$/',
'MY' => '/[0-9]{5}/',
'MV' => '/[0-9]{5}/',
'ML' => '/^\d{5}$/',
'MT' => '/[A-Z]{3} [0-9]{4}/',
'MH' => '/\d{5}(?:[-\s]\d{4})?/',
'MQ' => '/972[0-9]{2}/',
'MR' => '/^\d{5}$/',
'MU' => '/[0-9]{5}/',
'YT' => '/976[0-9]{2}/',
'MX' => '/[0-9]{5}/',
'MD' => '/MD-?[0-9]{4}/',
'MC' => '/980[0-9]{2}/',
'MN' => '/[0-9]{5}/',
'ME' => '/[0-9]{5}/',
'MS' => '/MSR [0-9]{4}/',
'MA' => '/[0-9]{5}/',
'MZ' => '/[0-9]{4}/',
'MM' => '/[0-9]{5}/',
'NA' => '/^\d{5}$/',
'NR' => '/^\d{5}$/',
'NP' => '/[0-9]{5}/',
'NL' => '/(?:NL-)?(\d{4})\s*([A-Z]{2})/',
'NC' => '/988[0-9]{2}/',
'NZ' => '/[0-9]{4}/',
'NI' => '/^\d{5}$/',
'NE' => '/[0-9]{4}/',
'NG' => '/[0-9]{6}/',
'NU' => '/^\d{5}$/',
'MP' => '/96950/',
'NO' => '/[0-9]{4}/',
'OM' => '/[0-9]{3}/',
'PK' => '/[0-9]{5}/',
'PW' => '/\d{5}(?:[-\s]\d{4})?/',
'PA' => '/[0-9]{4}/',
'PG' => '/[0-9]{3}/',
'PY' => '/[0-9]{4}/',
'PE' => '/[0-9]{5}/',
'PH' => '/[0-9]{4}/',
'PL' => '/[0-9]{2}-[0-9]{3}/',
'PT' => '/[0-9]{4}-[0-9]{3}/',
'PR' => '/\d{5}(?:[-\s]\d{4})?/',
'QA' => '/^\d{5}$/',
'RE' => '/974[0-9]{2}/',
'RO' => '/[0-9]{6}/',
'RU' => '/[0-9]{6}/',
'RW' => '/^\d{5}$/',
'WS' => '/WS[0-9]{4}/',
'ST' => '/^\d{5}$/',
'SA' => '/[0-9]{5}(-[0-9]{4})?/',
'SN' => '/[0-9]{5}/',
'RS' => '/[0-9]{5}/',
'SC' => '/^\d{5}$/',
'SL' => '/^\d{5}$/',
'SG' => '/[0-9]{6}/',
'SK' => '/[0-9]{3} [0-9]{2}/',
'SI' => '/[0-9]{4}/',
'SB' => '/^\d{5}$/',
'SO' => '/[A-Z]{2} [0-9]{5}/',
'ZA' => '/[0-9]{4}/',
'SS' => '/^\d{5}$/',
'ES' => '/[0-9]{5}/',
'LK' => '/[0-9]{4}/',
'BL' => '/[0-9]{5}/',
'VI' => '/\d{5}(?:[-\s]\d{4})?/',
'SE' => '/[0-9]{3} [0-9]{2}/',
'SH' => '/STHL 1ZZ/',
'KN' => '/[A-Z]{2}[0-9]{4}/',
'LC' => '/[A-Z]{2}[0-9]{2} [0-9]{3}/',
'SX' => '/^\d{5}$/',
'VC' => '/VC[0-9]{4}/',
'SD' => '/[0-9]{5}/',
'SR' => '/^\d{5}$/',
'SZ' => '/[A-Z]{1}[0-9]{3}/',
'CH' => '/[0-9]{4}/',
'SY' => '/^\d{5}$/',
'TW' => '/[0-9]{3}(-[0-9]{2})?/',
'TZ' => '/[0-9]{5}/',
'TH' => '/[0-9]{5}/',
'TG' => '/^\d{5}$/',
'TO' => '/^\d{5}$/',
'VG' => '/VG[0-9]{4}/',
'TT' => '/[0-9]{6}/',
'TN' => '/[0-9]{4}/',
'TR' => '/[0-9]{5}/',
'TM' => '/[0-9]{6}/',
'TC' => '/TKCA 1ZZ/',
'TV' => '/^\d{5}$/',
'UG' => '/^\d{5}$/',
'UA' => '/[0-9]{5}/',
'AE' => '/^\d{5}$/',
'GB' => '/([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9][A-Za-z]?))))\s?[0-9][A-Za-z]{2})/',
'US' => '/\d{5}(?:[-\s]\d{4})?/',
'UY' => '/[0-9]{5}/',
'UZ' => '/[0-9]{6}/',
'VU' => '/^\d{5}$/',
'VE' => '/[0-9]{4}(-[A-Z]{1})?/',
'VN' => '/[0-9]{6}/',
'YE' => '/^\d{5}$/',
'ZM' => '/[0-9]{5}/',
'ZW' => '/^\d{5}$/',
};
FYI denmark length 4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
json > js