ICAO MRZ Line 2 (Passport Data Line) Regex for JavaScript
/^([A-Z0-9<]{9})([0-9<])([A-Z]{3})(\d{6})([0-9<])([MFX<])(\d{6})([0-9<])([A-Z0-9<]{14})([0-9<])([0-9<])$/iWhat this pattern does
This page provides a comprehensive, battle-tested regular expression for matching icao mrz line 2 (passport data line), ported and verified for JavaScript. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// ICAO MRZ Line 2 (Passport Data Line)
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers
const icaoMrzLine2PassportDataLineRegex = /^([A-Z0-9<]{9})([0-9<])([A-Z]{3})(\d{6})([0-9<])([MFX<])(\d{6})([0-9<])([A-Z0-9<]{14})([0-9<])([0-9<])$/i;
function validateIcaoMrzLine2PassportDataLine(input: string): boolean {
return icaoMrzLine2PassportDataLineRegex.test(input);
}
// Example
console.log(validateIcaoMrzLine2PassportDataLine("L898902C36UTO7408122F1204159ZE184226B<<<<<11")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
L898902C36UTO7408122F1204159ZE184226B<<<<<11 | L898902C36UTO740812F1204159ZE184226B<<<<<1 |
AB1234567<USA8001010M2501016<<<<<<<<<<<<<<22 | L898902C36UTO7408122F120415ZE184226B<<<<<1 |
When to use this pattern
This pattern is drawn from the Identity & PII > Passport Numbers category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
Gender code X is used for non-binary/unspecified in ICAO Doc 9303 Amendment 8. Check digit validation requires the ICAO algorithm — format match alone is insufficient for fraud prevention.
Technical Notes
MRZ Line 2: 9-char passport number + check digit + 3-char nationality + 6-char DOB (YYMMDD) + check digit + gender (M/F/X/< ) + 6-char expiry + check digit + 14-char optional data + check digit + overall check digit. Capture groups: 1=passport number, 3=nationality, 4=DOB, 6=gender, 7=expiry.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern