Passport Number Regex
Validates a generic international passport number shape: a leading letter followed by 5 to 8 more letters or digits, for a total length of 6 to 9 alphanumeric characters.
Regex Pattern
^[A-Z][A-Z0-9]{5,8}$Default flags: i
Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the start of the string |
| [A-Z] | The first character, required to be a letter in most passport-issuing countries' formats |
| [A-Z0-9]{5,8} | 5 to 8 more characters, each a letter or digit, giving a total length of 6-9 characters |
| $ | Anchors the match to the end of the string |
Detailed Explanation
What it does
This pattern accepts a broad, format-only shape shared by many countries' passport numbers: it starts with a letter and is followed by a mix of letters and digits, for a total length between 6 and 9 characters. It is intentionally generic since there is no single global passport number standard.
Why it works
Most passport-issuing authorities (US, UK, India, and many others) start passport numbers with one or more letters followed by digits, and keep the total length in the 6-9 character range specified by ICAO Doc 9303 guidance for the machine-readable zone. A single leading letter plus a flexible alphanumeric tail covers this common shape without hard-coding any one country's exact scheme.
Common use cases
- First-pass client-side validation on international travel booking or visa forms
- Format sanity checks before calling a country-specific passport verification API
- Filtering scanned travel-document text (MRZ or OCR output) for passport-shaped tokens
- Guarding against obviously malformed input (too short, contains symbols) at the UI layer
Edge cases
- Some countries (e.g. Germany) issue all-digit or mixed passport numbers without a strict leading-letter rule, which a stricter country-specific pattern would need to relax
- The 'i' flag allows lowercase input like 'a1234567', which is normalized to uppercase by most systems anyway
- Passport numbers containing spaces or hyphens as printed on some cards will fail this compact pattern
- A 6-character result (letter + 5 alphanumerics) is the shortest accepted; some legacy passports use shorter numbers this pattern would reject
Limitations
- There is no single ISO standard for passport number format across all ~190 issuing countries, so this is a best-effort generic pattern, not authoritative
- Does not verify the passport is valid, unexpired, or actually issued
- For a specific country, a dedicated pattern (e.g. US: one letter + 8 digits) will be more accurate than this generic one
- Does not parse or validate the MRZ (machine-readable zone) checksum used on physical passport pages
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const passportRegex = /^[A-Z][A-Z0-9]{5,8}$/i;
console.log(passportRegex.test('A1234567')); // trueCommon Mistakes
Using this generic pattern as the sole validator for a specific country's passport, then rejecting valid numbers
Fix: Treat this as a fallback/first-pass check and swap in a country-specific pattern when the issuing country is known
Assuming a format match proves the passport is genuine or currently valid
Fix: Use a government or travel-industry verification API for authoritative document checks
Rejecting all-digit passport numbers outright
Fix: Some countries issue numeric-only passport numbers; relax the leading-letter requirement if you support those countries
Performance Notes
- The bounded {5,8} quantifier on a non-overlapping character class keeps matching linear with no catastrophic backtracking risk
- Anchors ensure the whole string is validated in a single pass rather than scanning for a substring match
- For high-volume validation across many countries, cache compiled per-country regexes rather than re-parsing pattern strings per request
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |