REGEXVAULTv2.0
Identity & PII/Passport Numbers
Verified Safe

ICAO MRZ Line 2 (Passport Data Line) Regex for Go

/^([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<])$/i

What 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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// ICAO MRZ Line 2 (Passport Data Line)
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers

package validation

import "regexp"

var icaoMrzLine2PassportDataLineRe = regexp.MustCompile(`^([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<])$`)

func ValidateIcaoMrzLine2PassportDataLine(s string) bool {
    return icaoMrzLine2PassportDataLineRe.MatchString(s)
}

// Example
// fmt.Println(ValidateIcaoMrzLine2PassportDataLine("L898902C36UTO7408122F1204159ZE184226B<<<<<11")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
L898902C36UTO7408122F1204159ZE184226B<<<<<11L898902C36UTO740812F1204159ZE184226B<<<<<1
AB1234567<USA8001010M2501016<<<<<<<<<<<<<<22L898902C36UTO7408122F120415ZE184226B<<<<<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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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