Credit Card Number Regular Expressions

Category: Numbers | Views Total: 98 views

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

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).

/^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/


Visa:

A regular expression to match Visa card numbers.

/^4[0-9]{12}(?:[0-9]{3})?$/


Mastercard:

A regular expression to match Mastercard numbers.

/^(?: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}$/


American Express:

A regular expression to match American Express card numbers.

/^3[47][0-9]{13}$/


Diners Club:

A regular expression to match Diners Club card numbers.

/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/


Discover:

A regular expression to match Discover card numbers.

/^6(?:011|5[0-9]{2})[0-9]{12}$/


JCB:

A regular expression to match JCB card numbers.

/^(?:2131|1800|35\d{3})\d{11}$/


Credit Card Number Examples:

  • Visa: 4012888888881881
  • MasterCard: 5555555555554444
  • American Express: 371449635398431
  • Diners Club: 38520000023237
  • Discover: 6011000990139424
  • JCB: 3566002020360505
Rate This Regex
Sending
User Review
0 (0 votes)

Leave a Reply