Last active
March 2, 2019 19:54
-
-
Save id4ehsan/a1ce9a8fb4b1388728611fb4faeb0cf6 to your computer and use it in GitHub Desktop.
Iranian National ID Checker in VBScript
This file contains hidden or 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 checkCodeMeli(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; | |
var c=parseInt(code.substr(9,1),10); | |
var s=0; | |
for(var 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)); | |
return true; | |
} |
This file contains hidden or 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
Dim ID | |
Dim sub_str | |
Dim Counter | |
Dim weighted_sum | |
ID = "0603293344" | |
For Counter = 1 to 9 Step 1 | |
sub_str = Mid(ID, Counter, 1) | |
weighted_sum = weighted_sum + (11-Counter)*CInt(sub_str) | |
Next | |
If (weighted_sum mod 11) < 2 Then | |
If (weighted_sum mod 11) = Mid(ID, 10, 1) Then | |
MsgBox("OK") | |
Else | |
MsgBox((weighted_sum mod 11)) | |
End If | |
Else | |
If (weighted_sum mod 11) = 11-Mid(ID, 10, 1) Then | |
MsgBox("OK") | |
Else | |
MsgBox(11-(weighted_sum mod 11)) | |
End If | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment