Valida CNPJ

@param string $cnpj
@return bool
333404
public static function cnpj(string $cnpj): bool
    {
        $cnpj = preg_replace('/[^0-9]/', '', (string)$cnpj);

        // Valida tamanho
        if (strlen($cnpj) != 14)
            return false;

        // Valida primeiro dígito verificador
        for ($i = 0, $j = 5, $soma = 0; $i < 12; $i++) {
            $soma += $cnpj{$i} * $j;
            $j = ($j == 2) ? 9 : $j - 1;
        }
        $resto = $soma % 11;
        if ($cnpj{12} != ($resto < 2 ? 0 : 11 - $resto))
            return false;

        // Valida segundo dígito verificador
        for ($i = 0, $j = 6, $soma = 0; $i < 13; $i++) {
            $soma += $cnpj{$i} * $j;
            $j = ($j == 2) ? 9 : $j - 1;
        }
        $resto = $soma % 11;
        return $cnpj{13} == ($resto < 2 ? 0 : 11 - $resto);
    }
420978
protected function validateFormatoCpfCnpj($attribute, $value)
    {
        return $this->validateFormatoCpf($attribute, $value) || $this->validateFormatoCnpj($attribute, $value);
    }
1328159
public function isValid($value, Constraint $constraint)
    {
        $document = $this->parseDocument($value);
        $fields = $this->parseFields($constraint->fields);
        $caseInsensitive = $this->parseCaseInsensitive($constraint->caseInsensitive);

        $query = $this->createQuery($document, $fields, $caseInsensitive);
        $numberResults = $query->count();

        if (0 === $numberResults) {
            return true;
        }

        if (1 === $numberResults) {
            $result = $query->one();
            if ($result === $document) {
                return true;
            }
        }

        if ($this->context) {
            $this->addFieldViolation($fields[0], $constraint->message);
        }

        return false;
    }
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;
    }
6257
public function isValid()
    {
        $blnReturn = true;

        $intDynamicCount = $this->getDynamicCount();

        for ($intCount = 0; $intCount <= $intDynamicCount; $intCount ++) {
            $blnReturn = $this->__validate($intCount);

            if (! $blnReturn) {
                break;
            }
        }

        return $blnReturn;
    }
743762
public function isValid($value = null, array $options = []): bool
    {
        if (\count($options) > 0) {
            $this->setOptions($options);
        }
        $this->setValue($value);
        $this->errors = [];

        $validIP = $this->validateIPNumber();
        $validPrivRange = $this->validatePrivateRange();
        $validResRange = $this->validateReservedRange();

        return $validIP && $validPrivRange && $validResRange;
    }
611436
public function requestValid()
    {
        $requestValid = true;

        $request = $this->getRequest();

        $ipnRequestVerifier = $this->getIPNRequestVerifier();
        $ipnRequestVerifier->setRequest($request);
        $ipnRequestVerifier->setShopOwner($this->getPayPalConfig()->getUserEmail());
        $requestCorrect = $ipnRequestVerifier->requestCorrect();

        if (!$requestCorrect) {
            $requestValid = false;

            $logger = $this->getLogger();
            $logger->setTitle("IPN VERIFICATION FAILURE BY PAYPAL");
            $logger->log($ipnRequestVerifier->getFailureMessage());
        }

        return $requestValid;
    }
1331864
public static function isValidCode($code)
    {
        if (array_key_exists($code, self::getInfoForCurrencies())) {
            return true;
        } elseif (array_key_exists($code, self::getInfoForCurrenciesWithoutCurrencyCode())) {
            return true;
        } elseif (array_key_exists($code, self::getInfoForCurrenciesWithUnofficialCode())) {
            return true;
        } elseif (array_key_exists($code, self::getInfoForCurrenciesWithHistoricalCode())) {
            return true;
        } else {
            return false;
        }
    }
502138
protected function isSyntacticallyValid(): bool
    {
        if (preg_match('!^([a-z][a-z0-9\+]*)://([^@]+@)?([^/?#]*)(/([^#?]*))?(.*)$!', $this->parsedUri->asString()) == 0) {
            return false;
        }

        if ($this->parsedUri->hasUser()) {
            if (preg_match('~([@:/])~', $this->parsedUri->user()) != 0) {
                return false;
            }

            if (!empty($this->parsedUri->password()) && preg_match('~([@:/])~', $this->parsedUri->password()) != 0) {
                return false;
            }
        }

        if (!$this->parsedUri->hasHostname() || strlen($this->parsedUri->hostname()) === 0) {
            return true;
        }

        if ($this->parsedUri->hasHostname()
          && preg_match('!^([a-zA-Z0-9\.-]+|\[[^\]]+\])(:([0-9]+))?$!', $this->parsedUri->hostname()) != 0) {
            return true;
        }

        return false;
    }
1233273
protected function validateCnh($attribute, $value)
    {
        // Trecho retirado do respect validation

        $ret = false;

        if ((strlen($input = preg_replace('/[^\d]/', '', $value)) == 11)
            && (str_repeat($input[1], 11) != $input)
        ) {
            $dsc = 0;

            for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) {

                $v += (int)$input[$i] * $j;

            }

            if (($vl1 = $v % 11) >= 10) {

                $vl1 = 0;
                $dsc = 2;

            }

            for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) {

                $v += (int)$input[$i] * $j;

            }

            $vl2 = ($x = ($v % 11)) >= 10 ? 0 : $x - $dsc;

            $ret = sprintf('%d%d', $vl1, $vl2) == substr($input, -2);
        }

        return $ret;
    }
1167903
public function validate(&$error = null)
    {
        if (!$this->isCountryCodeValid()) {
            $error = 'IBAN country code not valid or not supported';
        } elseif (!$this->isLengthValid()) {
            $error = 'IBAN length is invalid';
        } elseif (!$this->isFormatValid()) {
            $error = 'IBAN format is invalid';
        } elseif (!$this->isChecksumValid()) {
            $error = 'IBAN checksum is invalid';
        } else {
            $error = '';
            return true;
        }

        return false;
    }
590961
public function valid()
    {

        if ($this->container['contractId'] === null) {
            return false;
        }
        if ($this->container['issuerId'] === null) {
            return false;
        }
        if ($this->container['issuerCorporationId'] === null) {
            return false;
        }
        if ($this->container['assigneeId'] === null) {
            return false;
        }
        if ($this->container['acceptorId'] === null) {
            return false;
        }
        if ($this->container['type'] === null) {
            return false;
        }
        $allowedValues = $this->getTypeAllowableValues();
        if (!in_array($this->container['type'], $allowedValues)) {
            return false;
        }
        if ($this->container['status'] === null) {
            return false;
        }
        $allowedValues = $this->getStatusAllowableValues();
        if (!in_array($this->container['status'], $allowedValues)) {
            return false;
        }
        if ($this->container['forCorporation'] === null) {
            return false;
        }
        if ($this->container['availability'] === null) {
            return false;
        }
        $allowedValues = $this->getAvailabilityAllowableValues();
        if (!in_array($this->container['availability'], $allowedValues)) {
            return false;
        }
        if ($this->container['dateIssued'] === null) {
            return false;
        }
        if ($this->container['dateExpired'] === null) {
            return false;
        }
        return true;
    }
791230
public static function validate($grai)
    {
        if (strlen($grai) < 13) {
            return false;
        }
        $grai = self::unDecorate($grai);
        if (0 !== (int) $grai[0]) {
            return false;
        }
        $grai = substr($grai, 1, strlen($grai) - 1);
        if (strlen($grai) > 29) {
            return false;
        }
        $gtin13 = substr($grai, 0, 13);
        if (!ctype_alnum(substr($grai, 13, strlen($grai)))) {
            return false;
        }

        return parent::check($gtin13, 13); // optional serial component not to be checked
    }
1297462
protected function validateFileUploadCredential()
    {
        $upload = $this->request->file('file');

        if (empty($upload)) {

            if (!isset($this->data_credential['credential_id'])) {
                $this->setError('data.file', $this->text('File is required'));
                return false;
            }

            return null;
        }

        if ($this->isError()) {
            return null;
        }

        $result = $this->file_transfer->upload($upload, false, gplcart_file_private_module('gapi'));

        if ($result !== true) {
            $this->setError('data.file', $result);
            return false;
        }

        $file = $this->file_transfer->getTransferred();
        $decoded = json_decode(file_get_contents($file), true);

        if (empty($decoded['private_key'])) {
            unlink($file);
            $this->setError('data.file', $this->text('Failed to read JSON file'));
            return false;
        }

        if (isset($this->data_credential['data']['file'])) {
            $existing = gplcart_file_absolute($this->data_credential['data']['file']);
            if (file_exists($existing)) {
                unlink($existing);
            }
        }

        $this->setSubmitted('data.file', gplcart_file_relative($file));
        return true;
    }
855280
protected function validNonce($nonce)
    {
        $value = base64_decode($nonce);
        if ($value === false) {
            return false;
        }
        $parts = explode(':', $value);
        if (count($parts) !== 2) {
            return false;
        }
        list($expires, $checksum) = $parts;
        if ($expires < microtime(true)) {
            return false;
        }
        $secret = $this->getConfig('secret');
        $check = hash_hmac('sha1', $expires . ':' . $secret, $secret);

        return hash_equals($check, $checksum);
    }
1309062
public function validarCnpj($cnpj)
    {
        $cnpj = $this->filtrarSomenteNumeros($cnpj);

        // Valida tamanho e caracteres repetidos 00000000000000, 11111111111111, ..., 99999999999999
        if ((strlen($cnpj) != 14) || (preg_match('/(\d)\1{13}/', $cnpj))) {
            return false;
        }

        //Primeiro dígito verificador
        $soma = 0;
        $j = 5;
        for ($i = 0; $i < 12; $i++) {
            $soma += $cnpj{$i} * $j;
            $j = ($j == 2) ? 9 : $j - 1;
        }

        $resto = $soma % 11;
        if ($cnpj{12} != ($resto < 2 ? 0 : 11 - $resto)) {
            return false;
        }

        //Segundo dígito verificador
        $soma = 0;
        $j = 6;
        for ($i = 0; $i < 13; $i++) {
            $soma += $cnpj{$i} * $j;
            $j = ($j == 2) ? 9 : $j - 1;
        }

        $resto = $soma % 11;

        return $cnpj{13} == ($resto < 2 ? 0 : 11 - $resto);
    }
124264
public function isValid(): bool {
		return ($this->loginContext->hasCurrentUser()
				&& $this->loginContext->getCurrentUser()->isAdmin()) || N2N::isDevelopmentModeOn();
	}