← Back to all regex patterns
Validation
Low backtracking risk
Regex for Credit Card Number Format
This is a format-only pattern for card-like numbers. It is appropriate for client-side input cleanup, but real validation still needs Luhn checks and payment processor rules.
Regex
/^(?:\d[ -]*?){13,19}$/Try this pattern
Matches current input
4242 4242 4242 4242
1 match found in the current text.
Passing examples
- 4242 4242 4242 4242
- 5555-5555-5555-4444
Failing examples
- 1234
- card-4242
Code examples
JavaScript
const regex = /^(?:\d[ -]*?){13,19}$/g;
regex.test(input);Python
import re
pattern = re.compile(r"^(?:\d[ -]*?){13,19}$")
bool(pattern.search(input))Go
re := regexp.MustCompile("^(?:\\d[ -]*?){13,19}$")
matched := re.MatchString(input)Related Validation Patterns
Regex for Valid Email Address
/^[^\s@]+@[^\s@]+\.[^\s@]+$/i
Regex for URL Slug
/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Regex for Strong Password
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z\d]).{12,}$/
Regex for UUID v4
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
Regex for IPv4 Address
/^(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
Regex for Hex Color
/^#?(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/