Skip to main content
Regexflux

Any Credit Card Number

intermediate

Matches major credit card numbers (Visa, Mastercard, Amex, Discover).

credit-cardpaymentvalidationmulti-brand

Pattern

/(?:4\d{3}|5[1-5]\d{2}|3[47]\d{2}|6(?:011|5\d{2}))[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{1,4}/g

Try It

0 of 7 strings matched

Explanation

Matches Visa (4), Mastercard (51-55), Amex (34/37), and Discover (6011/65) card numbers with optional space or hyphen separators.

Test Strings

Matching

  • 4111111111111111
  • 5500000000000004
  • 371449635398431
  • 6011111111111117

Non-matching

  • 9999999999999999
  • abc
  • 12345

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:4\d{3}|5[1-5]\d{2}|3[47]\d{2}|6(?:011|5\d{2}))[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{1,4}/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns