Skip to content

Instantly share code, notes, and snippets.

@mikemix
Last active September 16, 2016 20:15
Show Gist options
  • Save mikemix/281f2054820d3b408f60 to your computer and use it in GitHub Desktop.
Save mikemix/281f2054820d3b408f60 to your computer and use it in GitHub Desktop.
<?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