ICAO MRZ Line 2 (Passport Data Line) Regex for PHP
/^([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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// ICAO MRZ Line 2 (Passport Data Line)
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers
define('ICAO_MRZ_LINE_2_PASSPORT_DATA_LINE_PATTERN', '/^([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<])$/');
function validate_icao_mrz_line_2_passport_data_line(string $input): bool {
return (bool) preg_match(ICAO_MRZ_LINE_2_PASSPORT_DATA_LINE_PATTERN, $input);
}
// Example
var_dump(validate_icao_mrz_line_2_passport_data_line("L898902C36UTO7408122F1204159ZE184226B<<<<<11")); // bool(true)Test 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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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