Created
June 11, 2020 13:28
-
-
Save mmcguff/9c8f7e284f22de54d5fd63358b6a01ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function isCCValid(ccNumberString) { | |
const patt = /^(?: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})$/; | |
if (ccNumberString.match(patt)) { | |
console.log("Credit Card is val"); | |
} | |
if (ccNumberString.match(patt)) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//Testing lines | |
let ans; | |
ans = isCCValid("5212123412341234"); | |
console.log(ans); | |
ans = isCCValid("7212123412341234"); | |
console.log(ans); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment