Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Created September 20, 2013 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sleavely/6639410 to your computer and use it in GitHub Desktop.
Save Sleavely/6639410 to your computer and use it in GitHub Desktop.
<?php
protected static function validatePNumber($pnumber) {
/* Check valid form (existing month and day) */
if (!preg_match("/^[0-9]{2}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))[0-9]{4}$/", $pnumber)) return false;
/* Calculate check sum and check wether or not the control digit is correct */
$sum = 0;
$x = 0;
for ($i = 0; $i < 10; $i++) {
$x = (int) $pnumber[$i];
if ($i % 2 == 0) {
$x = 2 * $x;
}
$sum += floor($x / 10) + ($x % 10);
}
return ($sum % 10 == 0);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment