REGEXVAULTv2.0
Identity & PII/Passport Numbers
Verified Safe

ICAO Machine-Readable Zone Line 1 (MRZ) Regex for PHP

/^P[A-Z<]([A-Z]{3})([A-Z0-9<]{39})$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching icao machine-readable zone line 1 (mrz), 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
<?php
// ICAO Machine-Readable Zone Line 1 (MRZ)
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers

define('ICAO_MACHINEREADABLE_ZONE_LINE_1_MRZ_PATTERN', '/^P[A-Z<]([A-Z]{3})([A-Z0-9<]{39})$/');

function validate_icao_machinereadable_zone_line_1_mrz(string $input): bool {
    return (bool) preg_match(ICAO_MACHINEREADABLE_ZONE_LINE_1_MRZ_PATTERN, $input);
}

// Example
var_dump(validate_icao_machinereadable_zone_line_1_mrz("P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<")); // bool(true)

Test Cases

Matches (Valid)
Rejects (Invalid)
P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<P<UTOERIKSSON<
P<GBRSMITH<<JOHN<WILLIAM<<<<<<<<<<<<<<<<<<<<A<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<
p<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<

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

< is the ICAO filler character (not a space). Double << separates surname from given names. Never OCR or store MRZ data without explicit purpose — MRZ contains a wealth of identifying information.

Technical Notes

MRZ Line 1 for passports: document type (P) + subtype + 3-char issuing country + surname<<given names, padded with < to 44 chars total. Line 2 contains the passport number, nationality, DOB, sex, expiry, and check digits.

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