Credit Card Number Regular Expressions

A collection of useful Regular Expressions to parse and validate Credit Card Numbers like Visa, MasterCard, American Express, Discover, etc.

There are a lot of regular expressions out there dedicated to parsing and validating credit card numbers. The purpose of this post is to collect a bunch of useful Regular expressions I found in a way that’s easy to use and understand. While this collection isn’t exhaustive, it covers the vast majority of cards you might come across.

All In One:

This is a general regular expression used to match Credit Card Numbers (Visa, MasterCard, American Express, Diners Club, Discover, and JCB cards).



A regular expression to match Visa card numbers.



A regular expression to match Mastercard numbers.


American Express:

A regular expression to match American Express card numbers.


Diners Club:

A regular expression to match Diners Club card numbers.



A regular expression to match Discover card numbers.



A regular expression to match JCB card numbers.


Credit Card Number Examples:

  • Visa: 4012888888881881
  • MasterCard: 5555555555554444
  • American Express: 371449635398431
  • Diners Club: 38520000023237
  • Discover: 6011000990139424
  • JCB: 3566002020360505


All the Regular Expressions in this blog post have been contributed by our readers. Some of them are contributed from external sources from sites such as, Stack Overflow, etc.

We aim to keep this resource updated with new and fresh content from our readers. We welcome anyone who wants to contribute a Regular Expression so they can benefit others.

You can submit a bug report for a regex or a bug request for a new regex at Submit Regex.

See Also: