Validates the country state condition
@param array $values
@return boolean|string
504776
public function stateId(array $values)
    {
        $count = count($values);
        $ids = array_filter($values, 'ctype_digit');

        if ($count != count($ids)) {
            return $this->translation->text('@field has invalid value', array(
                '@field' => $this->translation->text('Condition')));
        }

        $existing = array_filter($values, function ($state_id) {
            $state = $this->state->get($state_id);
            return isset($state['state_id']);
        });

        if ($count != count($existing)) {
            return $this->translation->text('@name is unavailable', array(
                '@name' => $this->translation->text('Country state')));
        }

        return true;
    }
780355
public function isValid($value)
    {
        $value = strtoupper($value);
        $this->_setValue($value);

        if (empty($this->_locale)) {
            $region = substr($value, 0, 2);
        } else {
            $region = new Zend_Locale($this->_locale);
            $region = $region->getRegion();
        }

        if (!array_key_exists($region, $this->_ibanregex)) {
            $this->_setValue($region);
            $this->_error(self::NOTSUPPORTED);
            return false;
        }

        if (!preg_match($this->_ibanregex[$region], $value)) {
            $this->_error(self::FALSEFORMAT);
            return false;
        }

        $format = substr($value, 4) . substr($value, 0, 4);
        $format = str_replace(
            array('A',  'B',  'C',  'D',  'E',  'F',  'G',  'H',  'I',  'J',  'K',  'L',  'M',
                  'N',  'O',  'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',  'X',  'Y',  'Z'),
            array('10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22',
                  '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35'),
            $format);

        $temp = intval(substr($format, 0, 1));
        $len  = strlen($format);
        for ($x = 1; $x < $len; ++$x) {
            $temp *= 10;
            $temp += intval(substr($format, $x, 1));
            $temp %= 97;
        }

        if ($temp != 1) {
            $this->_error(self::CHECKFAILED);
            return false;
        }

        return true;
    }
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;
    }
331625
private function isStringArray($values) {
        if (!is_array($values)) {
            return false;
        }

        return array_reduce($values, function($res, $value) {
            return $res && is_string($value);
        }, true);
    }
613891
protected static function filterConstant(array $values)
    {
        if (isset($values[1]) && in_array($values[1], self::VALID_CONSTANTS)) {
            $values[1] = constant($values[1]);
        }
        return $values[1];
    }
161514
public function isValid($value = null, $context = null)
    {
        if (!is_scalar($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $this->setValue($value);

        $country = $this->getCountry();

        if (!array_key_exists($country, self::$postCodeRegex) && array_key_exists($country, $context)) {
            $country = $context[$country];
        }

        if (!array_key_exists($country, self::$postCodeRegex)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        $format = self::$postCodeRegex[$country];

        if ($format[0] !== '/') {
            $format = '/^' . $format;
        }

        if ($format[strlen($format) - 1] !== '/') {
            $format .= '$/';
        }

        if (!preg_match($format, $value)) {
            $this->error(self::NO_MATCH);

            return false;
        }

        return true;
    }
1221936
protected function _validate($state)
    {
        // Unique values can't be null or empty string.
        if (empty($state->value) && !is_numeric($state->value)) {
            return false;
        }

        if (is_array($state->value)) {
            // The first element of the array can't be null or empty string.
            $first = array_slice($state->value, 0, 1);
            if (empty($first) && !is_numeric($first)) {
                return false;
            }
        }

        return true;
    }
675409
final public static function hasValue (...$values) : bool
	{
		foreach ($values as $value):
			if (is_array($value)):
				if (!(isset($value) AND (!empty($value)))):
					return FALSE; break;
				endif;
			else:
				$trimmedValue = trim($value);
				if (!(isset($trimmedValue) AND ($trimmedValue !== ""))):
					return FALSE; break;
				endif;
			endif;
		endforeach;
		return TRUE;
	}
411997
public function isValid($value, $context = null)
    {
        if (!is_scalar($value) || !is_numeric($value)) {
            $this->error(self::INVALID);

            return false;
        }

        $country = $this->getCountry();

        if (array_key_exists($country, $context)) {
            $country = $context[$country];
        }

        if (!in_array($country, $this->countrySupported, true)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        $aba = false;

        switch ($country) {
            case 'US':
                if (strlen($value) < 9) {
                    $this->error(self::TOO_SHORT);

                    return false;
                }

                if (strlen($value) > 9) {
                    $this->error(self::TOO_LONG);

                    return false;
                }

                $aba = (int) substr($value, 0, 2);
                break;
            case 'CA':
                if (strlen($value) < 8) {
                    $this->error(self::TOO_SHORT);

                    return false;
                }

                if (strlen($value) > 8) {
                    $this->error(self::TOO_LONG);

                    return false;
                }

                $aba = (int) substr($value, -3);
                break;
        }

        if (!is_int($aba)) {
            $this->error(self::UNSUPPORTED);

            return false;
        }

        /** @var array $abaLists */
        $abaLists = $this->aba[$country];
        $found    = false;

        foreach ($abaLists as $check) {
            if ($aba >= $check[0] && $aba <= $check[1]) {
                $found = true;
            }
        }

        if (!$found) {
            $this->error(self::NO_MATCH);

            return false;
        }

        if ($country === 'US') {
            /** @var string $value */
            $checksum = 7 * ($value[0] + $value[3] + $value[6]);
            $checksum += 3 * ($value[1] + $value[4] + $value[7]);
            $checksum += 9 * ($value[2] + $value[5]);

            if ($value[8] !== $checksum % 10) {
                $this->error(self::NO_MATCH);

                return false;
            }
        }

        return true;
    }
236563
public function hasCategoryValues($values)
    {
        $tagValues = $this->getCategoryValues(true);
        foreach ($this->filterCategoryValues($values) as $value) {
            if (!in_array($value, $tagValues)) {
                return false;
            }
        }
        return true;
    }
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;
    }
194252
protected function validateFormatCountry()
    {
        $field = 'format';
        $format = $this->getSubmitted($field);

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

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

        if (!is_array($format)) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        $default = $this->country->getDefaultFormat();

        if (!array_intersect_key($format, $default)) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        foreach ($format as $key => $value) {

            if (!is_array($value) || !array_intersect_key($value, $default[$key])) {
                $this->setErrorInvalid($field, $label);
                return false;
            }

            foreach ($value as $v) {
                if (!in_array(gettype($v), array('string', 'integer', 'boolean'))) {
                    $this->setErrorInvalid($field, $label);
                    return false;
                }
            }
        }

        return true;
    }
135094
public function isValid($vals)
    {
        $fields = $this->getFields();
        if (!Arr::iterable($fields)) {
            return true;
        }

        $result = true;

        // validate each field
        foreach ($fields as $k => $field) {
            // check if required
            if ($this->isRequired($field)) {
                if (!array_key_exists($k, $vals)
                        || is_null($vals[$k])
                        || $vals[$k] === ''
                        || $vals[$k] === false
                        || ($field['type'] === 'checkbox' && empty($vals[$k]))
                    ) {
                    $result = false;
                    $this->_messages[$k] = $this->getFieldRequiredMessage($k);
                    continue;
                }
            }

            // check maxlength
            if (array_key_exists('maxlength', $field)) {
                if (strlen($vals[$k]) > $field['maxlength']) {
                    $result = false;
                    $this->_messages[$k] = 'Value too long';
                    continue;
                }
            }

            // after this point, we're only checking values based on type
            if (!array_key_exists($k, $vals)) {
                continue;
            }
            if (!array_key_exists('type', $field)) {
                continue;
            }
 
            // Select
            if ($field['type'] === 'select') {
                if (!array_key_exists($vals[$k], $field['options'])) {
                    $result = false;
                    $this->_messages[$k] = 'Invalid option';
                }
                continue;
            }

            // Email
            if ($field['type'] === 'email') {
                if (!filter_var($vals[$k], FILTER_VALIDATE_EMAIL)) {
                    $result = false;
                    $this->_messages[$k] = 'Invalid email address';
                }
                continue;
            }

            // URL
            if ($field['type'] === 'url') {
                if (!filter_var($vals[$k], FILTER_VALIDATE_URL)) {
                    $result = false;
                    $this->_messages[$k] = 'Invalid URL';
                }
                continue;
            }

            // Color
            // http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
            if ($field['type'] === 'color') {
                if (!preg_match('/^#[0-9a-f]{6}$/i', $vals[$k])) {
                    $result = false;
                    $this->_messages[$k] = 'Invalid color';
                }
                continue;
            }
        }
        return $result;
    }
1186887
public function is_valid( $values ) {

		$this->input_data = [ 'value' => $values ];

		if ( ! is_array( $values ) && ! $values instanceof \Traversable ) {
			$this->error_code = Error\ErrorLoggerInterface::INVALID_TYPE_NON_TRAVERSABLE;

			return FALSE;
		}

		if ( ! $this->validate( $values ) ) {
			return FALSE;
		}

		if ( ! $this->validate_by_key( $values ) ) {
			return FALSE;
		}

		return TRUE;
	}
575968
public function validate(array $values, array $rules)
    {
        // Assume no validation and result success
        $result = true;

        if (true !== $valid = $this->validateByRules($rules, $values)) {
            foreach ($valid as $componentName => $error) {
                $this->setError($error, $componentName);
            }

            // Set general form error
            $this->setError(
                [
                    'error' => 'general',
                    'info'  => [],
                ],
                Doozr_Form_Service_Constant::ERROR_IDENTIFIER_FORM
            );

            $result = false;
        }

        return $result;
    }
1230222
public function validateInteger(array $values)
    {
        if (count($values) != 1) {
            $vars = array('@field' => $this->translation->text('Condition'));
            return $this->translation->text('@field has invalid value', $vars);
        }

        $value = reset($values);

        if (strlen($value) > 10) {
            $vars = array('@max' => 10, '@field' => $this->translation->text('Value'));
            return $this->translation->text('@field must not be longer than @max characters', $vars);
        }

        if (ctype_digit($value)) {
            return true;
        }

        $vars = array('@field' => $this->translation->text('Condition'));
        return $this->translation->text('@field has invalid value', $vars);
    }
391498
protected function filterNullValues(array $values)
    {
        $result = array_filter(
            $values,
            function($val) {
                return $val || 0 === $val || false === $val;
            }
        );

        return $result;
    }