Last active
September 16, 2016 20:15
-
-
Save mikemix/281f2054820d3b408f60 to your computer and use it in GitHub Desktop.
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
<?php | |
function peselValidate(string $str) | |
{ | |
if (!preg_match('/^[0-9]{11}$/', $str)) { | |
return false; | |
} | |
$arrSteps = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]; | |
$intSum = 0; | |
for ($i = 0; $i < 10; $i++) { | |
$intSum += $arrSteps[$i] * $str[$i]; | |
} | |
$int = 10 - $intSum % 10; | |
$intControlNr = ($int == 10) ? 0 : $int; | |
return $intControlNr === $str[10]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment