public function validate($vatNumber)
{
if (strlen($vatNumber) != 9) {
return false;
}
if (!is_numeric(substr($vatNumber, 1, 6))) {
return false;
}
$checksum = $vatNumber[8];
$fieldC1 = $vatNumber[0];
if (ctype_alpha($checksum) && in_array($fieldC1, $this->allowedC1Alphabetic)) {
// Juridical entities other than national ones
$checkval = $this->validateJuridical($vatNumber);
} elseif (ctype_digit($checksum) && in_array($fieldC1, $this->allowedC1Numeric)) {
// National juridical entities
$checkval = $this->validateNational($vatNumber);
} else {
return false;
}
if ($checksum != $checkval) {
return false;
}
return true;
}