Repository: validatorjs/validator.js
Pull request #2550 (2025-04-09 09:25:38)

fix(isPassportNumber): improve `US` locale
# Update isPassportNumber to include new US passport number alphanumeric format

**In the Next Generation US Passport, the passport number begins with a letter, followed by eight numbers.**

- Regex updated to support both old and new patterns:
  - Old: 9 digits, `/^\d{9}$/`
  - New: 1 letter + 8 digits, `/^[A-Z]\d{8}$/`
  - Combined: `/^\d{9}$|^[A-Z]\d{8}$/`
- Added test cases for the new pattern.

**Source:** [Information about the Next Generation U.S. Passport - travel.state.gov](https://travel.state.gov/content/travel/en/passports/passport-help/next-generation-passport.html)

## Checklist

- [x] PR contains only changes related; no stray files, etc.
- [x] README updated (where applicable)
- [x] Tests written (where applicable)
- [x] References provided in PR (where applicable)

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/validatorjs/validator.js/pull/2550?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`fde5ed5`)](https://app.codecov.io/gh/validatorjs/validator.js/commit/fde5ed5d9412bddc687662d5296770281ea9eb0b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs) to head [(`dd56325`)](https://app.codecov.io/gh/validatorjs/validator.js/commit/dd56325f70e7b59c68bf897a3530daa4d38b45a1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##            master     #2550   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2535      2535           
  Branches       641       641           
=========================================
  Hits          2535      2535           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/validatorjs/validator.js/pull/2550?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>

Patch:
diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js
index 33481e8..c3b842e 100644
--- a/src/lib/isPassportNumber.js
+++ b/src/lib/isPassportNumber.js
@@ -65,7 +65,7 @@ const passportRegexByCountryCode = {
   TH: /^[A-Z]{1,2}\d{6,7}$/, // THAILAND
   TR: /^[A-Z]\d{8}$/, // TURKEY
   UA: /^[A-Z]{2}\d{6}$/, // UKRAINE
-  US: /^\d{9}$/, // UNITED STATES
+  US: /^\d{9}$|^[A-Z]\d{8}$/, // UNITED STATES
   ZA: /^[TAMD]\d{8}$/, // SOUTH AFRICA
 };
 


Test patch:
diff --git a/test/validators.test.js b/test/validators.test.js
index 84bcaba..59be2d0 100644
--- a/test/validators.test.js
+++ b/test/validators.test.js
@@ -3615,11 +3615,15 @@ describe('Validators', () => {
       valid: [
         '790369937',
         '340007237',
+        'A90583942',
+        'E00007734',
       ],
       invalid: [
         'US0123456',
         '0123456US',
         '7903699371',
+        '90583942',
+        'E000077341',
       ],
     });