Skip to content

Instantly share code, notes, and snippets.

@josephjaniga
Last active August 29, 2015 14:22
Show Gist options
  • Save josephjaniga/206a5afc003eb3855452 to your computer and use it in GitHub Desktop.
Save josephjaniga/206a5afc003eb3855452 to your computer and use it in GitHub Desktop.
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