Validate Government VAT

@param  string $vatNumber

@return bool
965514
private function validateGovernment(string $vatNumber): bool
    {
        $prefix = strtoupper(substr($vatNumber, 0, 2));
        $number = (int) substr($vatNumber, 2, 3);

        // Government departments
        if ($prefix == 'GD') {
            return $number < 500;
        }

        // Health authorities
        if ($prefix == 'HA') {
            return $number > 499;
        }

        return false;
    }
1026538
public function validate($validator)
    {
        // false signifies invalid value due to failed parse()
        if ($this->value !== false) {
            return true;
        }

        $validator->validationError(
            $this->name,
            _t(
                'SilverStripe\\Forms\\NumericField.VALIDATION',
                "'{value}' is not a number, only numbers can be accepted for this field",
                ['value' => $this->originalValue]
            )
        );
        return false;
    }
135337
public function isValid($value)
    {
        $result = filter_var($value, FILTER_VALIDATE_INT);
        if (!$result) {
            $this->addMessage('number');
        }
        return ($result === false) ? false : true;
    }
1100014
private function validateBusiness(string $vatNumber): bool
    {
        $weights = [1, 2, 3, 4, 5, 6, 7, 8];
        $checkval = $this->sumWeights($weights, $vatNumber);

        if ($checkval % 11 == 10) {
            $weights = [3, 4, 5, 6, 7, 8, 9, 10];
            $checkval = $this->sumWeights($weights, $vatNumber);

            $checkval = ($checkval % 11) == 10 ? 0 : ($checkval % 11);
        } else {
            $checkval = $checkval % 11;
        }

        return $checkval == (int) $vatNumber[8];
    }
757578
private function validateIENew(string $vatNumber): bool
    {
        $checksum = strtoupper(substr($vatNumber, 7, 1));
        $checkNumber = substr($vatNumber, 0, 8);
        $checkval = 0;

        for ($i = 2; $i <= 8; $i++) {
            $checkval += (int)$checkNumber[8 - $i] * $i;
        }

        if (strlen($vatNumber) == 9) {
            $checkval += (9 * strpos($this->alphabet, $vatNumber[8]));
        }

        $checkval = ($checkval % 23);

        if ($checkval == 0) {
            return $checksum == 'W';
        }

        $checkchar = 'A';
        for ($i = $checkval - 1; $i > 0; $i--) {
            $checkchar++;
        }

        return $checkchar == $checksum;
    }
80875
private function isLengthValid()
    {
        $countryCode = $this->getCountryCode();
        $validLength = static::COUNTRY_CODE_LENGTH + static::CHECKSUM_LENGTH + static::$ibanFormatMap[$countryCode][0];

        return strlen($this->iban) === $validLength;
    }
279339
public function validarRucSociedadPrivada($numero = '')
    {
        // fuerzo parametro de entrada a string
        $numero = (string) $numero;

        // borro por si acaso errores de llamadas anteriores.
        $this->setError('');

        // validaciones
        try {
            $this->validarInicial($numero, '13');
            $this->validarCodigoProvincia(substr($numero, 0, 2));
            $this->validarTercerDigito($numero[2], 'ruc_privada');
            $this->validarCodigoEstablecimiento(substr($numero, 10, 3));
            $this->algoritmoModulo11(substr($numero, 0, 9), $numero[9], 'ruc_privada');
        } catch (Exception $e) {
            $this->setError($e->getMessage());

            return false;
        }

        return true;
    }
1218235
private function _checkVAT(&$vat)
    {
        if (!isset($vat)) {
            throw new Klarna_ArgumentNotSetException("VAT");
        }
        if (is_numeric($vat) && (!is_int($vat) || !is_float($vat))) {
            $vat = floatval($vat);
        }
        if (!is_numeric($vat) || (!is_int($vat) && !is_float($vat))) {
            throw new Klarna_InvalidTypeException("VAT", "integer or float");
        }
    }
987903
public static function validate($zipcode, $country = null)
    {
        $zipcode = trim($zipcode);
        $country = trim($country);
        if (empty($zipcode) || empty($country)) {
            return false;
        }

        $country = strtoupper($country);
        if (!isset(self::$patterns[$country])) {
            throw new \InvalidArgumentException("ERROR: The zipcode validator for $country does not exists yet: feel free to add it.");
        }

        return (bool) preg_match('/^('.self::$patterns[$country].')$/', $zipcode);
    }
992987
public function validate($validator)
    {
        // First check if value is numeric
        if ($this->value && $this->isNumeric()) {
            // Convert to a number to check
            $value = $this->value + 0;
            
            if(is_int($value)) {
                return true;
            }
        }
        
        $validator->validationError(
            $this->name,
            _t(
                'Checkout.VALIDATION', '{value} is not a valid number, only whole numbers can be accepted for this field',
                array('value' => $this->value)
            ),
            "validation"
        );
        return false;
    }
711071
public function validate($value)
    {
        if (!is_numeric($value)) {
            return false;
        }

        return $value / $this->number == round($value / $this->number);
    }
445703
public static boolean isValid(String organisasjonsnummer) {
		try {
			OrganisasjonsnummerValidator.getOrganisasjonsnummer(organisasjonsnummer);
			return true;
		} catch (IllegalArgumentException e) {
			return false;
		}
	}
1010330
public static function validate($mobileNumber)
    {
        $mobileNumber = Msisdn::clean($mobileNumber);

        return ! empty($mobileNumber) &&
        strlen($mobileNumber) === 10 &&
        is_numeric($mobileNumber);
    }
79419
public function doValidate()
    {
        $isValid = false;
        $answer = $this->valRaw();
        // http://en.wikipedia.org/wiki/Social_Security_number#Valid_SSNs
        // http://www.irs.gov/businesses/small/international/article/0,,id=96696,00.html#itin
        if (\preg_match('|^(\d{3})[\. -]?(\d{2})[\. -]?(\d{4})$|', $answer, $matches)) {
            list($area, $group, $serial) = \array_slice($matches, 1);
            if ($area >= 734 && $area <= 749 || $area > 772 && $area < 900 || $area == '666') {
                $isValid = false;
            } elseif ($area == '000' || $group == '00' || $serial == '0000') {
                $isValid = false;
            } elseif ($area == 987 && $group == 65 && \in_array($serial, \range(4320, 4329))) {
                $isValid = false;
            } else {
                $isValid = true;
            }
        }
        return $isValid;
    }
558607
public function validateDocument($documentNumber)
    {
        $data = $this->execute(
            self::HTTP_GET,
            self::DOMUSERP_API_PEDIDOVENDA . '/pessoas/validarDocumento',
            ['query' => ['num' => $documentNumber]]
        );

        return $data;
    }
565011
public static function validate($vat)
    {
        if (empty($vat) || null === $vat || '' === $vat) {
            return false;
        }

        $countryCode = substr($vat, 0, 2);
        if (false === self::isValidCountryCode($countryCode)) {
            return false;
        }

        $vat = substr($vat, 2);
        if (0 === preg_match('/^'.self::$patterns[$countryCode].'$/', $vat)) {
            return false;
        }

        return true;
    }
940997
function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        // Check "price inc/ex VAT" and "VAT type" fields.
        $vatTypeID = $http->postVariable( $base . '_ezprice_vat_id_' . $contentObjectAttribute->attribute( 'id' ) );
        $vatExInc = $http->postVariable( $base . '_ezprice_inc_ex_vat_' . $contentObjectAttribute->attribute( 'id' ) );
        if ( $vatExInc == 1 && $vatTypeID == -1 )
        {
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                 'Dynamic VAT cannot be included.' ) );
            return eZInputValidator::STATE_INVALID;
        }

        // Check price.
        if ( $http->hasPostVariable( $base . "_data_price_" . $contentObjectAttribute->attribute( "id" ) ) )
        {
            $data = $http->postVariable( $base . "_data_price_" . $contentObjectAttribute->attribute( "id" ) );

            $locale = eZLocale::instance();
            $data = $locale->internalCurrency( $data );
            $classAttribute = $contentObjectAttribute->contentClassAttribute();
            if( !$contentObjectAttribute->validateIsRequired() && ( $data == "" ) )
            {
                return eZInputValidator::STATE_ACCEPTED;
            }
            if ( preg_match( "#^[0-9]+(.){0,1}[0-9]{0,2}$#", $data ) )
                return eZInputValidator::STATE_ACCEPTED;

            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                 'Invalid price.' ) );
            return eZInputValidator::STATE_INVALID;
        }
        else if ( $contentObjectAttribute->validateIsRequired() )
        {
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', 'Input required.' ) );
            return eZInputValidator::STATE_INVALID;
        }
        else
        {
            return eZInputValidator::STATE_ACCEPTED;
        }
    }