Created
June 17, 2024 15:49
-
-
Save AliAlmasi/ebcad1fd532733a6e1d232cc3b4b9f81 to your computer and use it in GitHub Desktop.
Iranian ID number checker, implemented with JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function IrIdCheck(code) { | |
var L = code.length; | |
if (L < 8 || parseInt(code, 10) === 0) return false; | |
code = ('0000' + code).substr(L + 4 - 10); | |
if (parseInt(code.substr(3, 6), 10) === 0) return false; | |
int c = parseInt(code.substr(9, 1), 10); | |
int s = 0; | |
for (int i = 0; i < 9; i++) | |
s += parseInt(code.substr(i, 1), 10) * (10 - i); | |
s = s % 11; | |
return (s < 2 && c === s) || (s >= 2 && c === (11 - s)); | |
} | |
// Usage: | |
IrIdCheck("0361946762"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment