From bdb2ac79e942ebe711078ba831d4f0ac75cc0c1f Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Wed, 15 Jul 2026 06:20:56 -0400 Subject: [PATCH] fix(isPassportNumber): support case-insensitive country codes --- src/lib/isPassportNumber.js | 5 +++-- test/validators.test.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index aa0724cd7..c8373e80d 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -83,7 +83,8 @@ export default function isPassportNumber(str, countryCode) { assertString(str); /** Remove All Whitespaces, Convert to UPPERCASE */ const normalizedStr = str.replace(/\s/g, '').toUpperCase(); + const normalizedCountryCode = countryCode.toUpperCase(); - return (countryCode.toUpperCase() in passportRegexByCountryCode) && - passportRegexByCountryCode[countryCode].test(normalizedStr); + return (normalizedCountryCode in passportRegexByCountryCode) && + passportRegexByCountryCode[normalizedCountryCode].test(normalizedStr); } diff --git a/test/validators.test.js b/test/validators.test.js index f489105dd..10c1c40ca 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -3243,6 +3243,28 @@ describe('Validators', () => { ], }); + test({ + validator: 'isPassportNumber', + args: ['am'], + valid: [ + 'AF0549358', + ], + invalid: [ + 'A1054935', + ], + }); + + test({ + validator: 'isPassportNumber', + args: ['aM'], + valid: [ + 'AF0549358', + ], + invalid: [ + 'A1054935', + ], + }); + test({ validator: 'isPassportNumber',