Created
December 14, 2012 09:15
-
-
Save atree/4283939 to your computer and use it in GitHub Desktop.
Quick javascript to validate credit cards (MC, VISA, AMEX, DISCOVER)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cards = ['5555555555554444', '4222222222222', '4111111111111111', '4012888888881881', '378282246310005', '371449635398431', '378734493671000', '6011111111111117'] | |
regex = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9][0-9])[0-9]{12})|(3[47][0-9]{13}))$/ | |
for (c in cards) { console.log(regex.test(cards[c])) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment