UK Passport Number Regex for Go
/^[0-9]{9}$/All five implementations are free. Switch engines without signing in.
What this pattern does
This page provides a lightweight, single-purpose regular expression for matching uk 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
// UK Passport Number
// ReDoS-checked | RegexVault — Identity & PII > Passport Numbers
package validation
import "regexp"
var ukPassportNumberRe = regexp.MustCompile(`^[0-9]{9}$`)
func ValidateUkPassportNumber(s string) bool {
return ukPassportNumberRe.MatchString(s)
}
// Example
// fmt.Println(ValidateUkPassportNumber("123456789")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
123456789 | 12345678 |
000000001 | 1234567890 |
999999999 | 12345678A |
| — | 12-345-678 |
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 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 simple 9-digit format means any 9-digit number passes the regex check. Semantic validation (the number actually exists) requires checking against passport records, which is not publicly available.
Technical Notes
UK passport numbers are 9 digits. The format changed to a simple 9-digit number from an older alphanumeric format. HMPO (His Majesty's Passport Office) issues the numbers sequentially.
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