Mastercard Credit Card Number Regex Pattern
Validates Mastercard numbers starting with 51-55 or 2221-2720 in 16-digit format.
Live Regex Tester
Pattern Breakdown
Code Examples
JavaScript
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 test = "5500000000000004";
console.log(regex.test(test)); // true
// Extract matches
const matches = test.match(regex);
console.log(matches);Python
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}$'
test = "5500000000000004"
match = re.search(pattern, test)
print(match) # Found!Go
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")) // true
}Common Use Cases
Match Examples
| Input | Result |
|---|---|
| 5500000000000004 | Match |
| 4111111111111111 | No Match |
About the Mastercard Credit Card Number Regex
Validates Mastercard numbers starting with 51-55 or 2221-2720 in 16-digit format.
Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The mastercard credit card number pattern is classified as advanced difficulty in the financial category. It works in all major programming languages.
When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.
More Financial Patterns
Need More Regex Patterns?
Browse our complete library of 100+ regex patterns with interactive testers.
Frequently Asked Questions
What is the Mastercard Credit Card Number regex pattern?
Validates Mastercard numbers starting with 51-55 or 2221-2720 in 16-digit format.
How do I use the Mastercard Credit Card Number regex?
Use the 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}$/ in your code. In JavaScript: new RegExp('^(?: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}$', ''). Test it above with your own input.
What does this Mastercard Credit Card Number regex match?
This pattern matches: "5500000000000004". It does NOT match: "4111111111111111". Payment validation, transaction processing.
Is the Mastercard Credit Card Number regex beginner-friendly?
This pattern is rated Advanced. It uses advanced features like lookaheads, backreferences, or complex alternation.
What languages support the Mastercard Credit Card Number regex?
This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.
Can I modify the Mastercard Credit Card Number regex for my use case?
Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.