Skip to content

Instantly share code, notes, and snippets.

@pniel-cohen
Forked from etodanik/isracard.js
Created May 11, 2020 13:52
Show Gist options
  • Save pniel-cohen/2e4a977ec52d0796c4ac225d071a6036 to your computer and use it in GitHub Desktop.
Save pniel-cohen/2e4a977ec52d0796c4ac225d071a6036 to your computer and use it in GitHub Desktop.
Checks the validity of a given Isracard credit card number
function isracardCheck(num) {
if(num.length < 8 || num.length > 9) return false;
var diff = "987654321",
sum = 0,
a = 0,
b = 0,
c = 0;
if(num.length < 9) num = "0" + num;
for(var i=1;i<9;i++){
sum += parseInt(diff.substr(i,1))*parseInt(num.substr(i,1));
}
if(sum % 11 == 0) return true;
else return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment