Validates the field/value is a JSON string
@param array $submitted
@param array $options
@return array|bool
555116
public function json(array $submitted, array $options)
    {
        $options += array(
            'field' => null,
            'label' => null
        );

        $value = gplcart_array_get($submitted, $options['field']);

        json_decode($value);

        if (json_last_error() === JSON_ERROR_NONE) {
            return true;
        }

        return $this->setErrorInvalid($options['field'], $options['label']);
    }
287698
public function wishlist(array &$submitted, array $options)
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateWishlist();
        $this->validateProductWishlist();
        $this->validateUserCartId();
        $this->validateStoreId();

        $this->unsetSubmitted('update');

        return $this->getResult();
    }
531437
public function product(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateProduct();
        $this->validateSubtractProduct();
        $this->validateBool('status');
        $this->validateCurrencyProduct();
        $this->validateCategoryProduct();
        $this->validateUnitProduct();
        $this->validatePriceProduct();
        $this->validateStockProduct();
        $this->validateTitle();
        $this->validateDescription();
        $this->validateMetaTitle();
        $this->validateMetaDescription();
        $this->validateTranslation();
        $this->validateImages();
        $this->validateStoreId(false);
        $this->validateUserId(false);
        $this->validateDimensionProduct();
        $this->validateRelatedProduct();
        $this->validateClassProduct();
        $this->validateSkuProduct();
        $this->validateAttributeProduct();
        $this->validateCombinationProduct();
        $this->validateAlias();
        $this->validateUploadImages('product');

        $this->unsetSubmitted('update');

        return $this->getResult();
    }
291682
function validate($value, $options = null)
    {
        $length = core_text::strlen($value);
        switch ($this->name) {
            case 'minlength': return ($length >= $options);
            case 'maxlength': return ($length <= $options);
            default:          return ($length >= $options[0] && $length <= $options[1]);
        }
    }
876159
public function numeric(array $submitted, array $options)
    {
        $options += array(
            'field' => null,
            'label' => null
        );

        $value = gplcart_array_get($submitted, $options['field']);

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

        return $this->setErrorNumeric($options['field'], $options['label']);
    }
8386
public function language(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateLanguage();
        $this->validateWeight();
        $this->validateBool('status');
        $this->validateBool('default');
        $this->validateNameLanguage();
        $this->validateNativeNameLanguage();
        $this->validateCodeLanguage();

        $this->unsetSubmitted('update');

        return $this->getResult();
    }
652783
public function regexp(array $submitted, array $options)
    {
        $options += array(
            'field' => null,
            'label' => null,
            'arguments' => array()
        );

        $value = gplcart_array_get($submitted, $options['field']);

        if (empty($options['arguments']) || preg_match(reset($options['arguments']), $value) !== 1) {
            return $this->setErrorInvalid($options['field'], $options['label']);
        }

        return true;
    }
1239528
public function valid($options = array())
    {
        $options && $this->setOption($options);

        // Initialize the validation result to be true
        $this->result = true;

        $this->beforeValidate && call_user_func($this->beforeValidate, $this, $this->wei);

        foreach ($this->rules as $field => $rules) {
            $data = $this->getFieldData($field);

            /**
             * Process simple rule
             * FROM
             * 'username' => 'required'
             * TO
             * 'username' => array(
             *     'required' => true
             * )
             */
            if (is_string($rules)) {
                $rules = array($rules => true);
            } elseif ($rules instanceof BaseValidator) {
                $rules = array($rules);
            } elseif (!is_array($rules)) {
                throw new \InvalidArgumentException(sprintf(
                    'Expected argument of type array, string or instance of Wei\Validator\BaseValidator, "%s" given',
                    is_object($rules) ? get_class($rules) : gettype($rules)
                ));
            }

            // Make sure the "required" rule at first
            if (!isset($rules['required'])) {
                $isRequired = true;
            } else {
                $isRequired = (bool) $rules['required'];
                unset($rules['required']);
            }
            $rules = array('required' => $isRequired) + $rules;

            // Start validation
            foreach ($rules as $rule => $params) {
                // Prepare property options for validator
                $props = $this->prepareProps($field, $rule);

                // The current rule validation result
                /* @var $validator Validator\BaseValidator */
                $validator = null;
                $result = $this->validateOne($rule, $data, $params, $validator, $props);

                if (is_object($params)) {
                    $rule = get_class($params);
                }

                // Record the rule validators
                $this->ruleValidators[$field][$rule] = $validator;

                // If any rule is invalid, the result would always be false in the whole validation flow
                if (false === $result) {
                    $this->result = false;
                }

                // Record the valid/invalid rule
                $method = $result ? 'addValidRule' : 'addInvalidRule';
                $this->$method($field, $rule);

                // Trigger the ruleValid/ruleInvalid callback
                $callback = $result ? 'ruleValid' : 'ruleInvalid';
                if ($this->$callback && false === call_user_func($this->$callback, $rule, $field, $this, $this->wei)) {
                    return $this->result;
                }

                if ($result) {
                    // The field data is empty and optional, skip the remaining validation rules
                    /** @var $validator Validator\Required */
                    if ('required' === $rule && $validator->isInvalid($data)) {
                        break;
                    }
                } else {
                    // Break the validation flow when any field's rule is invalid
                    if ('required' === $rule || $this->breakRule || $this->skip) {
                        break;
                    }
                }
            }

            // Trigger the fieldValid/fieldInvalid callback
            $callback = $this->isFieldValid($field) ? 'fieldValid' : 'fieldInvalid';
            if ($this->$callback && false === call_user_func($this->$callback, $field, $this, $this->wei)) {
                return $this->result;
            }

            if (!$this->result && $this->skip) {
                continue;
            }

            // Break the validation flow when any field is invalid
            if (!$this->result && ($this->breakRule || $this->breakField)) {
                break;
            }
        }

        // Trigger the success/failure callback
        $callback = $this->result ? 'success' : 'failure';
        $this->$callback && call_user_func($this->$callback, $this, $this->wei);

        return $this->result;
    }
217126
public function validateCreate(&$submitted, $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateNameCreate();
        $this->validateDestinationCreate();

        return $this->getResult();
    }
839183
public function run($handler_id, &$submitted, array $options = array())
    {
        $result = null;
        $this->hook->attach('validator.run.before', $submitted, $options, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $result = $this->callHandler($handler_id, $submitted, $options);
        $this->hook->attach('validator.run.after', $submitted, $options, $result, $this);

        if ($result === true) {
            return true;
        }

        return empty($result) ? $this->translation->text('Failed validation') : $result;
    }
557345
public function address(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateAddress();
        $this->validateCountryAddress();

        $this->validateStateAddress();
        $this->validateCityAddress();
        $this->validateTypeAddress();
        $this->validateFieldsAddress();
        $this->validateUserIdAddress();
        $this->validateData();

        $this->unsetSubmitted('update');

        return $this->getResult();
    }
1067749
public function rating(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateProductRating();
        $this->validateUserId();
        $this->validateValueRating();

        return $this->getResult();
    }
648007
final public static function validateNumericFields (array $fields=[], string $option, string $field) : bool
	{
		$fieldsWithError 	= "";
		$field 				= static::checkGlobal($field);
		foreach ($fields as $fieldName => $length)
		{
			$value = static::setValueNull($field[$fieldName]);
			if ($value !== NULL) {
				$options = [$option => $length];
				if (!static::hasNumber($value, $options))
					$fieldsWithError .= "'".fieldNameAsText($fieldName)."', ";
			}
		}
		static::setError($fieldsWithError);
		return static::checkError();
	}
125544
public function validates($entity, $options = [])
    {
        $fieldname = $this->name();

        if (!isset($entity->{$fieldname})) {
            return true;
        }
        return $entity->{$fieldname}->validates($options);
    }
181041
protected function validate_valid_json_string($field, $input, $param = null)
    {
        if (!isset($input[$field]) || empty($input[$field])) {
            return;
        }

        if (!is_string($input[$field]) || !is_object(json_decode($input[$field]))) {
            return array(
              'field' => $field,
              'value' => $input[$field],
              'rule' => __FUNCTION__,
              'param' => $param,
            );
        }
    }
376219
public function validate($value, $options)
	{
		$this->value = $value;
		$this->options = $options;
		$this->errors = [];

		return $this->checkIt();
	}
636383
public function country(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateCountry();
        $this->validateWeight();
        $this->validateBool('status');
        $this->validateCodeCountry();
        $this->validateName();
        $this->validateNativeNameCountry();
        $this->validateZoneCountry();
        $this->validateFormatCountry();

        $this->unsetSubmitted('update');

        return $this->getResult();
    }