Discover Card Number Regex for Python
/^(?: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 Python. 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 Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.
Python Implementation
# Discover Card Number
# ReDoS-safe | RegexVault — Finance > Card Numbers
import re
discover_card_number_pattern = re.compile(r'^(?: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})$')
def validate_discover_card_number(value: str) -> bool:
return bool(discover_card_number_pattern.fullmatch(value))
# Example
print(validate_discover_card_number("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 Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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