Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/postcode-regexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@ export const POSTCODE_REGEXES: Map<string, RegExp> = new Map([
[CountryCode.WF, /^986\d{2}$/],
[CountryCode.XK, /^\d{5}$/],
[CountryCode.YT, /^976\d{2}$/],
[CountryCode.GI, /^GX11 1AA/],
[CountryCode.BT, /^\d{5}/],
[CountryCode.AL, /^\d{4}/],
[CountryCode.CU, /^\d{5}/],
[CountryCode.UM, /^96898/],
[CountryCode.AI, /^(?:AI-)?2640/],
[CountryCode.AF, /^\d{4}/],
[CountryCode.SD, /^\d{5}/],
[CountryCode.VC, /^VC\d{4}/],
[CountryCode.TA, /^TDCU 1ZZ/],
[CountryCode.NA, /^\d{5}/],
[CountryCode.EH, /^\d{5}/],
[CountryCode.BL, /^9[78][01]\d{2}/],
[CountryCode.TZ, /^\d{4,5}/],
[CountryCode.AC, /^ASCN 1ZZ/],
[CountryCode.VG, /^VG\d{4}/],
[CountryCode.MZ, /^\d{4}/],
[CountryCode.MF, /^9[78][01]\d{2}/],
[CountryCode.MM, /^\d{5}/],
[CountryCode.SV, /^CP [1-3][1-7][0-2]\d/],
[CountryCode.IR, /^\d{5}-?\d{5}/],
[CountryCode.PE, /^[0-2]\d{4}$/],
[CountryCode.INTL, /^(?:[A-Z0-9]+([- ]?[A-Z0-9]+)*)?$/i],
[CountryCode.CO, /^(0[58]|1[135789]|2[0357]|4[147]|5[024]|6[368]|7[036]|8[1568]|9[4579])\d{4}$/],
Expand Down
21 changes: 21 additions & 0 deletions src/postcode-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ export enum CountryCode {
XK = 'XK',
YT = 'YT',
PE = 'PE',
GI = "GI",
BT = "BT",
AL = "AL",
CU = "CU",
UM = "UM",
AI = "AI",
AF = "AF",
SD = "SD",
VC = "VC",
TA = "TA",
NA = "NA",
EH = "EH",
BL = "BL",
TZ = "TZ",
AC = "AC",
VG = "VG",
MZ = "MZ",
MF = "MF",
MM = "MM",
SV = "SV",
IR = "IR",
INTL = 'INTL',
CO = 'CO'
}
5 changes: 4 additions & 1 deletion test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('postcodeValidator', () => {
{ postcode: '01000', country: 'PE' },
{ postcode: '12345', country: 'TW' },
{ postcode: '123456', country: 'TW' },
{ postcode: '12341-12213', country: 'IR' },
];

expect.assertions(validPostcodes.length);
Expand All @@ -47,6 +48,7 @@ describe('postcodeValidator', () => {
{ postcode: '0100', country: 'PE' },
{ postcode: '010000', country: 'PE' },
{ postcode: '0A000', country: 'PE' },
{ postcode: '1121234', country: 'IR' },
];

expect.assertions(invalidPostcodes.length);
Expand All @@ -63,12 +65,13 @@ describe('postcodeValidator', () => {

describe('postcodeValidatorExistsForCountry', () => {
test('should return true for valid country code', () => {
expect.assertions(5);
expect.assertions(6);
expect(postcodeValidatorExistsForCountry('PR')).toBeTruthy();
expect(postcodeValidatorExistsForCountry('AU')).toBeTruthy();
expect(postcodeValidatorExistsForCountry('DE')).toBeTruthy();
expect(postcodeValidatorExistsForCountry('KY')).toBeTruthy();
expect(postcodeValidatorExistsForCountry('PE')).toBeTruthy();
expect(postcodeValidatorExistsForCountry('IR')).toBeTruthy();
});

test('should return false for invalid country code', () => {
Expand Down