Discover Card Number Regex for Go
/^(?:6011[0-9]{12}|64[4-9][0-9]{13}|65[0-9]{14}|622(?:1(?:2[6-9]|[3-9][0-9])|[2-8][0-9]{2}|9(?:[01][0-9]|2[0-5]))[0-9]{10})$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching discover card number, ported and verified for Go. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. 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
// Discover Card Number
// ReDoS-safe | RegexVault — Finance > Card Numbers
package validation
import "regexp"
var discoverCardNumberRe = regexp.MustCompile(`^(?:6011[0-9]{12}|64[4-9][0-9]{13}|65[0-9]{14}|622(?:1(?:2[6-9]|[3-9][0-9])|[2-8][0-9]{2}|9(?:[01][0-9]|2[0-5]))[0-9]{10})$`)
func ValidateDiscoverCardNumber(s string) bool {
return discoverCardNumberRe.MatchString(s)
}
// Example
// fmt.Println(ValidateDiscoverCardNumber("6011111111111117")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
6011111111111117 | 4111111111111111 |
6500000000000002 | 5500005555555559 |
6441111111111111 | 6010111111111117 |
6221261111111118 | 60111111111111170 |
When to use this pattern
This pattern is drawn from the Finance > Card 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
Discover cards are accepted on the UnionPay network in China and vice versa. The 622xxx range overlaps with UnionPay BINs — context determines which network to route to.
Technical Notes
Discover has multiple BIN ranges. The 622126-622925 range (UnionPay cobranded) was added later. Some validators miss the 644-649 and UnionPay ranges.
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