Skip to content

Instantly share code, notes, and snippets.

@josephjaniga josephjaniga/ccregex.js
Last active Aug 29, 2015

Embed
What would you like to do?
cc number regex by type
// CC Regex research
"http://www.regular-expressions.info/creditcard.html";
//Exhaustive List of CC Regex
"http://stackoverflow.com/a/23231321";
/**
* MASTERCARD
* Begins with 51-55 - Total 16 digits
*/
/**
* VISA
* Begins with "4"
* New Cards are 16 digits total
* Older Cards are 13 digits total
*/
/**
* AmericanExpress
* Being with "34" or "37
* 15 Digits Total
*/
/**
* DinersClub
* Begin with 300-305 or 36, 38 - 14 Digits Total
* Some Being with 5 and have 16 Digits - (considered Mastercard)
*/
/**
* Discover
* Begin with 6011 or 65
* Total 16 Digits
*/
/**
* JCB
* Cards that begin with: 2131, 1800 total 15 digits
* Cards that being with: 35 total 16 digits
*/
var MasterCardPattern = /^5[1-5][0-9]{14}$/,
VisaPattern = /^4[0-9]{12}(?:[0-9]{3})?$/,
AmericanExpressPattern = /^3[47][0-9]{13}$/,
DinersClubPattern = /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
DiscoverPattern = /^6(?:011|5[0-9]{2})[0-9]{12}$/,
JCBPattern = /^(?:2131|1800|35[0-9]{3})[0-9]{11}$/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.