Skip to content

Commit 5baa37a

Browse files
committed
Update isPassport validator to cover new Canadian passport number format
- 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
1 parent a7d5cff commit 5baa37a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/lib/isPassportNumber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const passportRegexByCountryCode = {
1616
BG: /^\d{9}$/, // BULGARIA
1717
BR: /^[A-Z]{2}\d{6}$/, // BRAZIL
1818
BY: /^[A-Z]{2}\d{7}$/, // BELARUS
19-
CA: /^[A-Z]{2}\d{6}$/, // CANADA
19+
CA: /^[A-Z]{2}\d{6}$|^[A-Z]\d{6}[A-Z]{2}$/, // CANADA
2020
CH: /^[A-Z]\d{7}$/, // SWITZERLAND
2121
CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/, // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
2222
CY: /^[A-Z](\d{6}|\d{8})$/, // CYPRUS

test/validators.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,9 +3085,17 @@ describe('Validators', () => {
30853085
valid: [
30863086
'GA302922',
30873087
'ZE000509',
3088+
'A123456AB',
3089+
'Z556378HG',
30883090
],
30893091
invalid: [
30903092
'AB0123456',
3093+
'AZ556378H',
3094+
'556378HCX',
3095+
'556378432',
3096+
'5563784',
3097+
'#B12345FD',
3098+
'A43F12354',
30913099
],
30923100
});
30933101

0 commit comments

Comments
 (0)