Skip to content

Instantly share code, notes, and snippets.

@pouyadarabi
Created September 8, 2020 10:33
Show Gist options
  • Save pouyadarabi/02fcc7b841357186268b69bda28d9a09 to your computer and use it in GitHub Desktop.
Save pouyadarabi/02fcc7b841357186268b69bda28d9a09 to your computer and use it in GitHub Desktop.
http://www.are.ir/article/shenasameli/shenasa_meli.htm تبدیل شده از کد PHP بررسی صحت شناسه ملی حقوقی در
function isValidLegalNationalID($code)
{
$length = strlen($code);
if ($length < 11 || intval($code) == 0)
return false;
if (intval(substr($code, 3, 6)) == 0) return false;
$c = intval(substr($code, 10, 1));
$d = intval(substr($code, 9, 1)) + 2;
$z = [29, 27, 23, 19, 17];
$s = 0;
for ($i = 0; $i < 10; $i++) {
$s += ($d + intval(substr($code, $i, 1))) * $z[$i % 5];
}
$s = $s % 11;
if ($s == 10)
$s = 0;
return $c == $s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment