Schengen / EU Passport Number (Generic) Regex for Go
/^[A-Z0-9]{8,9}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching schengen / eu passport number (generic), 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
// Schengen / EU Passport Number (Generic)
// ReDoS-safe | RegexVault — Identity & PII > Passport Numbers
package validation
import "regexp"
var schengenEuPassportNumberGenericRe = regexp.MustCompile(`^[A-Z0-9]{8,9}$`)
func ValidateSchengenEuPassportNumberGeneric(s string) bool {
return schengenEuPassportNumberGenericRe.MatchString(s)
}
// Example
// fmt.Println(ValidateSchengenEuPassportNumberGeneric("C01X00T47")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
C01X00T47 | 1234567 |
PA0000001 | 1234567890 |
12345678 | AB 1234 |
AB1234567 | AB-1234 |
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
No uniform EU passport number format exists — each country determines its own structure. Always capture the issuing country alongside the passport number.
Technical Notes
EU member states each have their own passport number format within the 8-9 character alphanumeric space. DE: C01X00T47 (old format), FR: starts with two letters, IT: AA0000000, ES: PAA000000. Use country-specific patterns when the issuing country is known.
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