Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MajideND/3edbd6f9b67cb108b66f133be6dd3640 to your computer and use it in GitHub Desktop.
Save MajideND/3edbd6f9b67cb108b66f133be6dd3640 to your computer and use it in GitHub Desktop.
A simple validation for companies national number (تایید صحت شناسه ملی به زبان پی اچ پی)
public function checkShenaseMelli($shenase)
{
if (strlen($shenase) != 11)
return false;
if (intval(substr($shenase, 3, 6)) == 0)
return false;
$c = intval(substr($shenase, 10, 1));
$d = intval(substr($shenase, 9, 1)) + 2;
$z = array(29, 27, 23, 19, 17);
$s = 0;
for ($i = 0; $i < 10; $i++) {
$s += ($d + intval(substr($shenase, $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