HomeRegex LibraryCredit Card Number (Visa / Master / Amex) Regex
100% Client-Side β€’ 0 B Data Leaves Browser
validation

Credit Card Number (Visa / Master / Amex) Regex

Validates primary card major industry identifiers for Visa, MasterCard, American Express, and Discover.

Regular Expression Pattern:
/^(?: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})$/
Valid Match Example:
4111111111111111
Invalid / Non-Match Example:
1234567890123456

Regex Syntax Breakdown & Explanation

  • β€’4[0-9]{12}(?:[0-9]{3})? : Visa card format (13 or 16 digits starting with 4)
  • β€’5[1-5][0-9]{14} : MasterCard format (16 digits starting 51-55)
  • β€’3[47][0-9]{13} : American Express format (15 digits starting 34 or 37)

Implementation in Popular Languages

JavaScript / TypeScript
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})$/;
const isValid = regex.test("4111111111111111");
console.log(isValid); // true
Python (re)
import re

pattern = 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})$"
match = re.match(pattern, "4111111111111111")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := 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})$`)
  fmt.Println(re.MatchString("4111111111111111"))
}
Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The regular expression pattern is /^(?: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})$/. Validates primary card major industry identifiers for Visa, MasterCard, American Express, and Discover.