ramblings about cars, tech, web development and more. BOTB Winner in 2010

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!

Previous

Exporting Weight data from Garmin Connect

Next

How to easily transfer Epub’s and PDF’s to your kindle

2 Comments

  1. 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

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.

Powered by WordPress & Theme by Anders Norén