public function isValid($value) : bool
{
// Removes spaces
$companyId = preg_replace('~\\s+~', '', (string) $value);
// Only numbers
if (!preg_match('~^\\d{8}$~', $companyId)) {
return false;
}
// Checksum
$a = 0;
for ($i = 0; $i < 7; $i++) {
$a += $companyId[$i] * (8 - $i);
}
$a = $a % 11;
if (0 === $a) {
$c = 1;
} elseif (10 === $a) {
$c = 1;
} elseif (1 === $a) {
$c = 0;
} else {
$c = 11 - $a;
}
if ((int) $companyId[7] !== $c) {
return false;
}
return true;
}