Skip to content

Instantly share code, notes, and snippets.

@mmcguff
Created June 11, 2020 13:28
Show Gist options
  • Save mmcguff/9c8f7e284f22de54d5fd63358b6a01ad to your computer and use it in GitHub Desktop.
Save mmcguff/9c8f7e284f22de54d5fd63358b6a01ad to your computer and use it in GitHub Desktop.
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