Indian PIN Code Regex for Go
/^[1-9][0-9]{5}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching indian pin code, ported and verified for Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. 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
// Indian PIN Code
// ReDoS-safe | RegexVault — Localization > Postal Codes
package validation
import "regexp"
var indianPinCodeRe = regexp.MustCompile(`^[1-9][0-9]{5}$`)
func ValidateIndianPinCode(s string) bool {
return indianPinCodeRe.MatchString(s)
}
// Example
// fmt.Println(ValidateIndianPinCode("110001")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
110001 | 01001 |
400001 | 10000 |
700001 | 1100001 |
600001 | 11000A |
500001 | 0 |
When to use this pattern
This pattern is drawn from the Localization > Postal Codes 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
Not all 6-digit combinations starting with 1-9 are valid PIN codes — validate against India Post's postal database for confirmed delivery. Military Field Post Offices (FPO) use codes in the 900xxx range.
Technical Notes
Indian PIN code structure: first digit = postal zone (1-9, excludes 0), second digit = sub-zone, third digit = sorting district, last 3 digits = individual post office. Delhi is 110xxx, Mumbai is 400xxx.
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