Skip to content

Instantly share code, notes, and snippets.

@MRezaSafari
Created November 17, 2021 15:09
Show Gist options
  • Save MRezaSafari/970c74aa23607da454fcd2775e84a359 to your computer and use it in GitHub Desktop.
Save MRezaSafari/970c74aa23607da454fcd2775e84a359 to your computer and use it in GitHub Desktop.
function isValidIranianNationalCode(input) {
if (!/^\d{10}$/.test(input))
return false;
var check = parseInt(input[9]);
var sum = 0;
var i;
for (i = 0; i < 9; ++i) {
sum += parseInt(input[i]) * (10 - i);
}
sum %= 11;
return (sum < 2 && check == sum) || (sum >= 2 && check + sum == 11);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment