public static function personId($check)
{
$pattern = '/^[12]\\d{2}(0\\d|1[012])(\\d{2}|2[AB])\\d{8}$/';
if (!preg_match($pattern, $check)) {
return false;
}
$numberWithoutKey = substr($check, 0, -2);
$key = substr($check, -2);
// Corse special cases
// source : http://xml.insee.fr/schema/nir.html
// check : http://www.parodie.com/monetique/nir.htm
if ($numberWithoutKey[6] == 'A') {
$numberWithoutKey = str_replace('A', '0', $numberWithoutKey);
$numberWithoutKey -= 1000000;
} elseif ($numberWithoutKey[6] == 'B') {
$numberWithoutKey = str_replace('B', '0', $numberWithoutKey);
$numberWithoutKey -= 2000000;
}
return $key == 97 - ($numberWithoutKey - floor($numberWithoutKey / 97) * 97);
}