Recently I needed to validate MRZ passport numbers using the Machine Readable Passport Zone (MRZ) numbers and PHP.
My weapon of choice is PHP but I’ve included the raw REGEX too to help others. I used High Programmer to understand the parts of the code and then REGEXR to help test my REGEX codes.
MRZ line 1: [A-Z0-9<]{2}[A-Z<]{3}[A-Z0-9<]{39}
$regex = ‘^[A-Z0-9<]{2}[A-Z<]{3}[A-Z0-9<]{39}$^’;
$result = preg_match($regex, $value);
returns TRUE or FALSE
MRZ Line 2: [A-Z0-9<]{9}[0-9]{1}[A-Z<]{3}[0-9]{6}[0-9]{1}[FM<]{1}[0-9]{6}[0-9]{1}[A-Z0-9<]{14}[0-9]{1}[0-9]{1}
$regex = ‘^[A-Z0-9<]{9}[0-9]{1}[A-Z<]{3}[0-9]{6}[0-9]{1}[FM<]{1}[0-9]{6}[0-9]{1}[A-Z0-9<]{14}[0-9]{1}[0-9]{1}$^’;
$result = preg_match($regex, $value);
returns TRUE or FALSE
I hope this is useful to you!
Imran
Hi there, I wonder when would it be needed to validate mrz numbers, what type of website or app might need it. Please share if u dont’ mind
AlunR
Hi Imran,
We use it in conjunction with an identity checking API service to validate customers.