Skip to content

Instantly share code, notes, and snippets.

@maysam
Created August 14, 2015 17:42
Show Gist options
  • Save maysam/2fda2e5f1faa62ed7cd1 to your computer and use it in GitHub Desktop.
Save maysam/2fda2e5f1faa62ed7cd1 to your computer and use it in GitHub Desktop.
function verifyNationalCode(source, arguments) {
var nationalCode = arguments.Value;
arguments.IsValid = false;
if (nationalCode.length != 10)
return;
if (nationalCode == "0000000000" || nationalCode == "1111111111" || nationalCode == "2222222222" ||
nationalCode == "3333333333" || nationalCode == "4444444444" || nationalCode == "5555555555" ||
nationalCode == "6666666666" || nationalCode == "7777777777" || nationalCode == "8888888888" ||
nationalCode == "9999999999")
return;
n = parseInt(nationalCode.charAt(0)) * 10 +
parseInt(nationalCode.charAt(1)) * 9 +
parseInt(nationalCode.charAt(2)) * 8 +
parseInt(nationalCode.charAt(3)) * 7 +
parseInt(nationalCode.charAt(4)) * 6 +
parseInt(nationalCode.charAt(5)) * 5 +
parseInt(nationalCode.charAt(6)) * 4 +
parseInt(nationalCode.charAt(7)) * 3 +
parseInt(nationalCode.charAt(8)) * 2;
c = parseInt(nationalCode.charAt(9));
r = n % 11;
if ((r < 2 && r == c) || (r >= 2 && c == 11 - r))
arguments.IsValid = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment