Created
June 8, 2024 10:48
-
-
Save MajideND/3edbd6f9b67cb108b66f133be6dd3640 to your computer and use it in GitHub Desktop.
A simple validation for companies national number (تایید صحت شناسه ملی به زبان پی اچ پی)
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
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