HomeRegex LibraryMastercard Credit Card Number Regex
100% Client-Side β€’ 0 B Data Leaves Browser
security

Mastercard Credit Card Number Regex

Validates 16-digit Mastercard card numbers across traditional 51-55 series and 2221-2720 2-series ranges.

Regular Expression Pattern:
/^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/
Valid Match Example:
5500000000000004
Invalid / Non-Match Example:
4500000000000004

Regex Syntax Breakdown & Explanation

  • β€’5[1-5] : Traditional Mastercard bin range 51 through 55
  • β€’222[1-9]|... : Modern 2-series BIN ranges introduced in 2017
  • β€’[0-9]{12}$ : Remaining 12 subscriber account digits

Implementation in Popular Languages

JavaScript / TypeScript
const regex = /^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/;
const isValid = regex.test("5500000000000004");
console.log(isValid); // true
Python (re)
import re

pattern = r"^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$"
match = re.match(pattern, "5500000000000004")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$`)
  fmt.Println(re.MatchString("5500000000000004"))
}
Frequently Asked Questions

Frequently Asked Questions

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

The regular expression pattern is /^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/. Validates 16-digit Mastercard card numbers across traditional 51-55 series and 2221-2720 2-series ranges.