REGEXVAULTv2.0
Identity & PII/Passport Numbers
Verified Safe

Indian Passport Number Regex for Go

/^[ABCDEFGHIJKLMNPRSTUVWYZ][0-9]{7}$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching indian passport number, 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
// Indian Passport Number
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers

package validation

import "regexp"

var indianPassportNumberRe = regexp.MustCompile(`^[ABCDEFGHIJKLMNPRSTUVWYZ][0-9]{7}$`)

func ValidateIndianPassportNumber(s string) bool {
    return indianPassportNumberRe.MatchString(s)
}

// Example
// fmt.Println(ValidateIndianPassportNumber("A1234567")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
A1234567A123456
Z9999999A12345678
P123456711234567
K1234567a1234567
O1234567
Q1234567

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

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. Free submissions join the queue. Priority review available for $15.

Submit a Pattern