Indian Passport Number Regex for Python
/^[ABCDEFGHIJKLMNPRSTUVWYZ][0-9]{7}$/All five implementations are free. Switch engines without signing in.
What this pattern does
This page provides a well-structured, multi-part regular expression for matching indian passport number, ported and verified for Python. 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 Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.
Python Implementation
# Indian Passport Number
# ReDoS-checked | RegexVault — Identity & PII > Passport Numbers
import re
indian_passport_number_pattern = re.compile(r'^[ABCDEFGHIJKLMNPRSTUVWYZ][0-9]{7}$')
def validate_indian_passport_number(value: str) -> bool:
return bool(indian_passport_number_pattern.fullmatch(value))
# Example
print(validate_indian_passport_number("A1234567")) # TrueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
A1234567 | A123456 |
Z9999999 | A12345678 |
P1234567 | 11234567 |
K1234567 | a1234567 |
| — | O1234567 |
| — | Q1234567 |
When to use this pattern
This pattern is drawn from the Identity & PII > Passport Numbers category and has been checked for ReDoS risk. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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
The excluded letters (O, Q, X) change over time as passport offices cycle through prefixes. The safest approach is to allow all letters and reject O and X specifically, checking Q against current MEA guidance.
Technical Notes
Indian passports use letters A-Z excluding O, Q, X (reserved). The letter roughly indicates the issuing authority and period. First letter: A-Z (excluding O, Q, X) assigned to different Passport Seva Kendras. Currently issued letters: B, H, J, K, L, M, N, P, R, T, V, W, Y, Z.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Submissions join the review queue after automated validation.
Submit a Pattern