In Iran each person has a national code which is called “Code Melli” or “کد ملی”. And, its algorithm is very similar to ISBN algorithm:
The rules are:
1- This number has 10 digits like: C[1] C[2] C[3] C[4] C[5] C[6] C[7] C[8] C[9] C[10]
2- 3 digits of left must not be equal to 000 (c[1]c[2]c[3]000)
3- C[10] is a control digit (like ISBN algorithm)
The formula to determine C[10] is:
Let A = (C[1]*10)+ (C[2]*9)+ (C[3]*8)+ (C[4]*7)+ (C[5]*6)+ (C[6]*5)+ (C[7]*4)+ (C[8]*3)+ (C[9]*2)
Let B = A MOD 11
If B == 0 Then C[10]=B Else C[10] = 11-B
This JavaScript function is useful to validation:
<script>
//————— Begin Iranian national code checker function —————
// Usage: IsIRNationalCode(‘Number’) Return -> True-False
// Copyright: Soroush Dalili – October 2008
//
/**
* IsIRNationalCode is a function to validate Iranian National ID
* @param theNum National ID number as an input
* @return true if the input number is a valid Iranian National ID, otherwise false
*/
function IsIRNationalCode(theNum)
{
if(theNum.length!=10)
{
return false;
}
else
{
if(theNum.substr(0,3)==’000′) return false;
var check = 0;
for(var i=0;i< theNum.length;i++)
{
var num = theNum.substr(i,1);
check += num*(10-i)
}
if(check%11)
{
return false;
}
else
{
return true;
}
}
}
// Copyright: Soroush Dalili – October 2008
//————— End Iranian national code checker function —————
</script>