Jyxo\Input\Validator\IsTaxId::isValid PHP Method

isValid() public method

Validates a value.
public isValid ( mixed $value ) : boolean
$value mixed Input value
return boolean
    public function isValid($value) : bool
    {
        // Removes spaces
        $taxId = preg_replace('~\\s+~', '', (string) $value);
        // Group tax ID format since 1st January 2009
        if (preg_match('~^CZ699\\d{6}$~', $taxId, $matches)) {
            return true;
        }
        $sub = '';
        // New Tax ID format since 1st May 2004
        if (preg_match('~^CZ(\\d{8,10})$~', $taxId, $matches)) {
            $sub = $matches[1];
            // But to be sure we try the old one as well
        } elseif (preg_match('~^\\d{3}-(\\d{8,10})$~', $taxId, $matches)) {
            $sub = $matches[1];
        }
        if (!empty($sub)) {
            // Strict checking off - allows the so called "own numbers"
            if (!$this->strict) {
                return true;
            }
            // Checks if it is a valid IČ
            if (IsCompanyId::validate($sub)) {
                return true;
            }
            // Checks if it is a valid birth number
            if (IsBirthNumber::validate($sub)) {
                return true;
            }
        }
        return false;
    }