Skip to content

Instantly share code, notes, and snippets.

@alirezas
Last active February 3, 2020 09:43
Show Gist options
  • Save alirezas/33bb570c41a388c16324 to your computer and use it in GitHub Desktop.
Save alirezas/33bb570c41a388c16324 to your computer and use it in GitHub Desktop.
Iran National Code Validation
function validateNationalNumber(value) {
if (value == '0000000000' ||
value == '1111111111' ||
value == '2222222222' ||
value == '3333333333' ||
value == '4444444444' ||
value == '5555555555' ||
value == '6666666666' ||
value == '7777777777' ||
value == '8888888888' ||
value == '9999999999')
{
return false;
}
var c = parseInt(value.charAt(9));
var n = parseInt(value.charAt(0)) * 10 +
parseInt(value.charAt(1)) * 9 +
parseInt(value.charAt(2)) * 8 +
parseInt(value.charAt(3)) * 7 +
parseInt(value.charAt(4)) * 6 +
parseInt(value.charAt(5)) * 5 +
parseInt(value.charAt(6)) * 4 +
parseInt(value.charAt(7)) * 3 +
parseInt(value.charAt(8)) * 2;
var r = n - parseInt(n/11)*11;
if ((r == 0 && r == c) || (r == 1 && c == 1) || (r > 1 && c == 11 - r)) {
return true;
}
else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment