Credit Card Regex Tester
Test and validate credit-card patterns with this specialized regex tester. Includes tested patterns and real-time matching.
Recommended Credit-card Pattern
``regex
^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$
`
Test Examples
Valid matches:
- 4111111111111111
4111-1111-1111-11114111 1111 1111 1111
Invalid (should not match):
4111111111111114111-1111-1111abcd-efgh-ijkl-mnop
Pattern Explanation
Matches 16-digit card numbers with optional spaces or dashes
Alternative Patterns
1. ^\d{16}$
2. ^(?:\d{4}[- ]?){4}$`
How to Use
1. The pattern above is preloaded—or enter your own 2. Add test strings to validate 3. See real-time match highlights 4. Copy the pattern for your code
Regex Quick Reference
| Symbol | Meaning | Example | \dAny digit\d{3} matches "123" \wWord character\w+ matches "hello" +One or morea+ matches "aaa" *Zero or morea* matches "" or "aaa" ?Optionalcolou?r matches "color" ^Start of string^Hello $End of stringworld$ [abc]Character class[aeiou] matches vowels (ab)Alternation(catdog) matches either