Regex for Credit Card Number
Matches major credit card numbers: Visa, Mastercard, American Express, Diners Club, and Discover. Does not validate checksum.
Pattern
/^(?:4\d{12}(?:\d{3})?|5[1-5]\d{14}|3[47]\d{13}|3(?:0[0-5]|[68]\d)\d{11}|6(?:011|5\d{2})\d{12})$/Pattern Breakdown
| Token | Explanation |
|---|---|
| 4\d{12}(?:\d{3})? | Visa: starts with 4, 13 or 16 digits |
| 5[1-5]\d{14} | Mastercard: starts with 51-55, 16 digits |
| 3[47]\d{13} | Amex: starts with 34 or 37, 15 digits |
| 3(?:0[0-5]|[68]\d)\d{11} | Diners Club: starts with 300-305 or 36/38, 14 digits |
| 6(?:011|5\d{2})\d{12} | Discover: starts with 6011 or 65, 16 digits |
Test Examples
| Input | Match? |
|---|---|
| 4111111111111111 | Match |
| 5500000000000004 | Match |
| 371449635398431 | Match |
| 1234567890123456 | No match |
| 411111111111111 | No match |
Common Use Cases
- Payment form validation
- Card number format checking
- PCI compliance scanning
Variations
^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$16 digits with optional separators
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester