From 05a3c18e9b40a32bfec247f8a9e8aabcccf3f701 Mon Sep 17 00:00:00 2001 From: Keshav Date: Fri, 5 Jun 2026 22:05:56 +0530 Subject: [PATCH] feat: add postal code validation for TR, PH, MA, and VN --- src/lib/isPostalCode.js | 4 ++++ test/validators.test.js | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 185cd5f1b..c7808a58c 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -50,6 +50,7 @@ const patterns = { LU: fourDigit, LV: /^LV\-\d{4}$/, LK: fiveDigit, + MA: fiveDigit, MC: /^980\d{2}$/, MG: threeDigit, MX: fiveDigit, @@ -61,6 +62,7 @@ const patterns = { NZ: fourDigit, // https://www.pakpost.gov.pk/postcodes.php PK: fiveDigit, + PH: fourDigit, PL: /^\d{2}\-\d{3}$/, PR: /^00[679]\d{2}([ -]\d{4})?$/, PT: /^\d{4}\-\d{3}?$/, @@ -73,9 +75,11 @@ const patterns = { SK: /^\d{3}\s?\d{2}$/, TH: fiveDigit, TN: fourDigit, + TR: fiveDigit, TW: /^\d{3}(\d{2,3})?$/, UA: fiveDigit, US: /^\d{5}(-\d{4})?$/, + VN: fiveDigit, ZA: fourDigit, ZM: fiveDigit, }; diff --git a/test/validators.test.js b/test/validators.test.js index a4c3d7193..2ffac6535 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -13407,6 +13407,59 @@ describe('Validators', () => { 'ab1234', ], }, + { + locale: 'TR', + valid: [ + '01000', + '34000', + '81000', + ], + invalid: [ + '1000', + '340000', + 'ab123', + ], + }, + { + locale: 'PH', + valid: [ + '1000', + '1200', + '6000', + '8000', + ], + invalid: [ + '100', + '10000', + 'ab12', + ], + }, + { + locale: 'MA', + valid: [ + '10000', + '20000', + '30000', + ], + invalid: [ + '1000', + '200000', + 'ab123', + ], + }, + { + locale: 'VN', + valid: [ + '10000', + '70000', + '90000', + ], + invalid: [ + '1000', + '700000', + 'ab123', + ], + }, ]; let allValid = [];