Validate MRZ passport numbers with Regex and PHP

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!

Posted in php

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.