Skip to content

fix(isPassportNumber): improve CA locale #2526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

evanbechtol
Copy link
Contributor

@evanbechtol evanbechtol commented Feb 7, 2025

Update isPassportNumber to cover both new and old Canadian passport number formats

  • Regex now covers both of the following patterns:

    • Old pattern of: 2 letters, followed by 6 digits
    • New pattern of: 1 letter, 6 digits, 2 letters
  • Modify existing CA isPassportNumber regular expression to cover new format and old format.

  • Update test cases to cover new format, and add additional invalid passport number cases

Old format: /^[A-Z]{2}\d{6}$
New format: ^[A-Z]\d{6}[A-Z]{2}$/
Combined into a single regular expression: /^[A-Z]{2}\d{6}$|^[A-Z]\d{6}[A-Z]{2}$/

Sources

closes: #2525

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

- Regex now covers both of the following patterns:
  -  Old pattern of: 2 letters, followed by 6 digits
  - New pattern of: 1 letter, 6 digits, 2 letters
@evanbechtol evanbechtol changed the title Update isPassport validator to cover new Canadian passport number format fix:(isPassport does not support new Canadian Passport Number Format) Feb 7, 2025
@WikiRik WikiRik changed the title fix:(isPassport does not support new Canadian Passport Number Format) fix(isPassportNumber): improve CA locale Mar 26, 2025
@WikiRik WikiRik merged commit 7ab06c4 into validatorjs:master Mar 26, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isPassport does not support new Canadian Passport Number Format
3 participants