Aarunya AppsAarunya Apps

Credit Card NumberRegex — Pattern, Examples & Code

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$

What it matches / doesn't match

Matches ✅Does not match ❌
41111111111111111234567890123456
55000055555555594111 1111 1111 1111
378282246310005411111111111

How it works

Matches major card networks: Visa (starts with 4, 13 or 16 digits), Mastercard (starts with 51–55, 16 digits), American Express (starts with 34 or 37, 15 digits), and Discover (starts with 6011 or 65, 16 digits). This checks format only — always run Luhn algorithm validation server-side to verify a card number is potentially valid.

Code Usage

JavaScript

const regex = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$/;
regex.test("4111111111111111"); // true

Python

import re
pattern = re.compile(r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$')
bool(pattern.match("4111111111111111"))  # True

Go

import "regexp"
r := regexp.MustCompile(`^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$`)
r.MatchString("4111111111111111") // true

Need a custom regex for a different use case?

Generate a custom regex with AI →

FAQ

What does the Credit Card Number regex pattern match?

Matches major card networks: Visa (starts with 4, 13 or 16 digits), Mastercard (starts with 51–55, 16 digits), American Express (starts with 34 or 37, 15 digits), and Discover (starts with 6011 or 65, 16 digits). This checks format only — always run Luhn algorithm validation server-side to verify a card number is potentially valid.

How do I use the Credit Card Number regex in JavaScript?

const regex = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$/; regex.test("4111111111111111"); // true

Can I use the Credit Card Number regex in Python?

Yes. import re pattern = re.compile(r'^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$') bool(pattern.match("4111111111111111")) # True