Validates canadian province two character abbr
@author paul.visco@roswellpark.org
@version 1.2 13/18/2008

@param string $province
@return \sb\Validate_Results
975081
public static function province($province) {

        $result = new \sb\Validate\Results();
        $result->value = $province;

        if (in_array($province, self::provinces)) {

            $result->is_valid = true;
            $result->message = 'Valid province code';
        } else {

            $result->is_valid = false;
            $result->message = 'Invalid province code, are you sure you are using a two letter abbreviation';
        }

        return $result;
    }
923706
public function validate($value) {
        if($this->sanitizable->getRawValue()===$value) {
            return new ValidationResult(true);
        }
        
        return new ValidationResult(false, 'The given value contains illegal characters');
    }
572258
public static function validate($value)
    {
        if (!is_array($value)) {
            return false;
        }
        if (!isset($value['from'])) {
            return false;
        }
        if (AddressValidator::validate($value['from']) === false) {
            return false;
        }
        if (isset($value['to']) && AddressValidator::validate($value['to']) === false && $value['to'] !== '') {
            return false;
        }
        if (isset($value['gas']) && QuantityValidator::validate($value['gas']) === false) {
            return false;
        }
        if (isset($value['gasPrice']) && QuantityValidator::validate($value['gasPrice']) === false) {
            return false;
        }
        if (isset($value['value']) && QuantityValidator::validate($value['value']) === false) {
            return false;
        }
        // if (!isset($value['data'])) {
        //     return false;
        // }
        // if (HexValidator::validate($value['data']) === false) {
        //     return false;
        // }
        if (isset($value['data']) && HexValidator::validate($value['data']) === false) {
            return false;
        }
        if (isset($value['nonce']) && QuantityValidator::validate($value['nonce']) === false) {
            return false;
        }
        return true;
    }
12038
public function validateAttribute($model, $attribute)
    {
        $country = '';
        if ($this->country !== null) {
            $country = $this->country;
        } elseif ($this->countryAttribute !== null) {
            $country = $model->{$this->countryAttribute};
        } elseif ($this->countryCodeAttribute !== null) {
            $country = $model->{$this->countryCodeAttribute};
        }
        // if empty country and used strict mode
        if (empty($country) && $this->strict) {
            $this->addError($model, $attribute, Yii::t('app', $this->strictModeMessage));

            return false;
        }
        if (empty($country)) {
            return true;
        }
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $numberProto = $phoneUtil->parse($model->$attribute, $country);
            if ($phoneUtil->isValidNumber($numberProto)) {
                if ($this->format) {
                    $model->$attribute = $phoneUtil->format($numberProto, PhoneNumberFormat::INTERNATIONAL);
                }

                return true;
            } else {
                $this->addError($model, $attribute, Yii::t('app', $this->message));

                return false;
            }
        } catch (NumberParseException $e) {
            $this->addError($model, $attribute, Yii::t('app', $this->numberParseExceptionMessage));
        }
    }
1244522
public static function validate($html)
    {
        $curlHandler = curl_init('https://validator.nu/?out=gnu');

        curl_setopt($curlHandler, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $html);
        curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curlHandler, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($curlHandler, CURLOPT_HTTPHEADER, [
            'Content-type: text/html; charset=utf-8',
            'Content-Length: ' . strlen($html),
        ]);

        $result = curl_exec($curlHandler);

        if (curl_getinfo($curlHandler, CURLINFO_HTTP_CODE) !== 200) {
            throw new RuntimeException('Curl error (are you connected to Internet?): ' . curl_error($curlHandler));
        }

        return $result;
    }
597695
protected function validateCountryCity()
    {
        $field = 'country';

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

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Country');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        $country = $this->country->get($value);

        if (empty($country['code'])) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        $this->setSubmitted('country', $country['code']);
        return true;
    }
459897
protected function validWBMP($data)
	{
		return ord($data[0]) === 0 && ord($data[1]) === 0 && $data !== substr(TypeJp2::JPEG_2000_SIGNATURE, 0, self::LONG_SIZE);
	}
414728
protected function validateIban($attribute, $value, $parameters)
    {
        // Since IBAN's has different lengths depending on which country
        // the IBAN it comes from. We unfortunately needs this rather ugly
        // array with country codes and a value which corrosponds to the length
        // of the IBAN in that given country
        $countryIbanLengths = [
            'AL' => 28, 'AD' => 24, 'AT' => 20, 'AZ' => 28, 'BH' => 22, 'BE' => 16, 'BA' => 20, 'BR' => 29,
            'BG' => 22, 'CR' => 21, 'HR' => 21, 'CY' => 28, 'CZ' => 24, 'DK' => 18, 'DO' => 28, 'TL' => 23,
            'EE' => 20, 'FO' => 18, 'FI' => 18, 'FR' => 27, 'GE' => 22, 'DE' => 22, 'GI' => 23, 'GR' => 27,
            'GL' => 18, 'GT' => 28, 'HU' => 28, 'IS' => 26, 'IE' => 22, 'IL' => 23, 'IT' => 27, 'JO' => 30,
            'KZ' => 20, 'XK' => 20, 'KW' => 30, 'LV' => 21, 'LB' => 28, 'LI' => 21, 'LT' => 20, 'LU' => 20,
            'MK' => 19, 'MT' => 31, 'MR' => 27, 'MU' => 30, 'MC' => 27, 'MD' => 24, 'ME' => 22, 'NL' => 18,
            'NO' => 15, 'PK' => 24, 'PS' => 29, 'PL' => 28, 'PT' => 25, 'QA' => 29, 'RO' => 24, 'SM' => 27,
            'SA' => 24, 'RS' => 22, 'SK' => 24, 'SI' => 19, 'ES' => 24, 'SE' => 24, 'CH' => 21, 'TN' => 24,
            'TR' => 26, 'AE' => 23, 'GB' => 22, 'VG' => 24, 'DZ' => 24, 'AO' => 25, 'BJ' => 28, 'BF' => 27,
            'BI' => 16, 'CM' => 27, 'CV' => 25, 'IR' => 26, 'CI' => 28, 'MG' => 27, 'ML' => 28, 'MZ' => 25,
            'SN' => 28, 'UA' => 29,
        ];

        // Prepare string for validation
        $value = str_replace(' ', '', strtoupper($value));

        // Grab country of IBAN
        $countryCode = substr($value, 0, 2);

        // Retrieve IBAN length
        $countryIbanLength = ! empty($countryIbanLengths[$countryCode]) ? $countryIbanLengths[$countryCode] : 0;

        // Validate IBAN length
        if ($countryIbanLength == 0 || strlen($value) != $countryIbanLength) {
            return false;
        }

        // Generate data for later checksum calculation
        $checksumData = [];
        foreach (range('A', 'Z') as $letter) {
            $checksumData[$letter] = strval($letter);
        }

        // Prepare for generation of checksum
        $value = substr($value, 4).substr($value, 0, 4);
        $value = str_replace(array_keys($checksumData), array_values($checksumData), $value);

        // Generate checksum
        $checksum = intval($value[0]);
        for ($i = 1; $i < strlen($value); $i++) {
            $checksum *= 10;
            $checksum += intval($value[$i]);
            $checksum %= 97;
        }

        // Verify checksum
        return $checksum == 1;
    }
119114
private function isValidPlaceholderCharacter($character)
    {
        $asciiCode = ord($character);

        return (($asciiCode >= 48) && ($asciiCode <= 57))
            || (($asciiCode >= 65) && ($asciiCode <= 90))
            || (($asciiCode >= 97) && ($asciiCode <= 122));
    }
1177312
public function validate($locale)
    {
        if (!$locale) {
            return false;
        }
        $lang = $this->langFromLocale($locale);
        $region = $this->countryFromLocale($locale);
        if (!$lang || !$region) {
            return false;
        }

        // Check the configurable whitelist
        $localeCode = strtolower($lang) . '_' . strtoupper($region);
        $locales = $this->getLocales();

        if (array_key_exists($localeCode, $locales)
            || array_key_exists(strtolower($localeCode), $locales)
        ) {
            return true;
        }

        // Fallback
        return strcasecmp($lang, $region)
            && strcasecmp($lang, $locale)
            && strcasecmp($region, $locale);
    }
286939
public static function validate($value)
    {
        if (!is_array($value)) {
            return false;
        }
        if (isset($value['from']) && IdentityValidator::validate($value['from']) === false) {
            return false;
        }
        if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
            return false;
        }
        if (!isset($value['topics']) || !is_array($value['topics'])) {
            return false;
        }
        foreach ($value['topics'] as $topic) {
            if (IdentityValidator::validate($topic) === false) {
                return false;
            }
        }
        if (!isset($value['payload'])) {
            return false;
        }
        if (HexValidator::validate($value['payload']) === false) {
            return false;
        }
        if (!isset($value['priority'])) {
            return false;
        }
        if (QuantityValidator::validate($value['priority']) === false) {
            return false;
        }
        if (!isset($value['ttl'])) {
            return false;
        }
        if (isset($value['ttl']) && QuantityValidator::validate($value['ttl']) === false) {
            return false;
        }
        return true;
    }
1039621
protected function _isLengthValid($sIBAN)
    {
        $iActualLength = getStr()->strlen($sIBAN);

        $iCorrectLength = $this->_getLengthForCountry($sIBAN);

        return !is_null($iCorrectLength) && $iActualLength === $iCorrectLength;
    }
316792
public function validateRegion()
    {
        if (! in_array($this->region, $this->regions)) {
            return self::REGION_DEFUALT;
        }

        return $this->region;
    }
768047
public function validateRule(Rule $rule, array $restrictions = array())
    {
        /** @var \Claroline\CoreBundle\Rule\Constraints\AbstractConstraint[] $usedConstraints */
        $usedConstraints = array();
        $existedConstraints = $this->getConstraints();

        foreach ($existedConstraints as $existedConstraint) {
            if ($existedConstraint->isApplicableTo($rule)) {
                $usedConstraints[] = $existedConstraint->setRule($rule);
            }
        }

        $validatedConstraints = 0;
        $nbConstraints = count($usedConstraints);

        $associatedLogs = $this->getAssociatedLogs($usedConstraints, $restrictions);

        foreach ($usedConstraints as $usedConstraint) {
            $usedConstraint->setAssociatedLogs($associatedLogs);

            if ($usedConstraint->validate()) {
                ++$validatedConstraints;
            }
        }

        return ($validatedConstraints === $nbConstraints) ? $associatedLogs : false;
    }
187605
public function origin($province = null, $id = null)
    {
        return $this->request($this->api_version . '/internationalOrigin', [
            'province' => $province,
            'id' => $id,
        ]);
    }
117666
public static function validate($phone, $region = 'RU')
    {
        try {
            return self::phoneUtil()->isValidNumberForRegion(self::phoneUtil()->parse($phone, $region), $region);
        } catch (NumberParseException $e) {
            return false;
        }
    }
1127540
public function validate($content)
    {
        if (!$content) {
            return false;
        }
        if (preg_match('/[A-Z]/', $content)) {
            return false;
        } elseif (mb_strpos($content, self::PARSE_DELIMITER) === 0) {
            $this->errorMsg = self::PARSE_DELIMITER . ' is not allowed to be at the beginning of the callname';

            return false;
        } elseif (mb_strpos($content, self::PARSE_DELIMITER) == (strlen($content) - 1)) {
            $this->errorMsg = self::PARSE_DELIMITER . ' is not allowed to be at the end of the callname';

            return false;
        } elseif (preg_match($this->invalidCharacters, $content)) {
            $this->errorMsg = $this->invalidCharacters . ' are not allowed to be in the callname';

            return false;
        }

        return true;
    }