From 8754507bd39f0410657991dfc34afef89b121148 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 20 Dec 2022 00:35:29 +0100 Subject: [PATCH 1/2] fix(isPostalCode): Fix overly permissive BY regexp * add missing start of line anchor * remove meaningless `{1}` quantifier Fixes #2133 --- src/lib/isPostalCode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index cf5b50d25..0635b06fb 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -15,7 +15,7 @@ const patterns = { BE: fourDigit, BG: fourDigit, BR: /^\d{5}-\d{3}$/, - BY: /2[1-4]{1}\d{4}$/, + BY: /^2[1-4]\d{4}$/, CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i, CH: fourDigit, CN: /^(0[1-7]|1[012356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[1-5]|8[1345]|9[09])\d{4}$/, From 843584e9684af742f8b8f24f43e7cd8b88c8d688 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 20 Dec 2022 20:59:16 +0100 Subject: [PATCH 2/2] test(validators): add invalid tests for isPostalCode locale BY --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index c0e36bec7..5fa430c76 100644 --- a/test/validators.js +++ b/test/validators.js @@ -11262,6 +11262,12 @@ describe('Validators', () => { '247710', '231960', ], + invalid: [ + 'test 225320', + '211120 test', + '317543', + '267946', + ], }, { locale: 'CA',