Created
September 20, 2013 15:35
-
-
Save Sleavely/6639410 to your computer and use it in GitHub Desktop.
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
<?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