Validates data against the set validation rules

Returns boolean true when successful validate without errors.

@param array $skip
Optional array of fieldnames to skip on validation

@return boolean
164002
protected function validate(array &$data, array $fields = [], bool $filter_before_validate = true, array $skip = [])
    {
        static $validator;

        if (empty($fields)) {

            // No and no fields in scheme means no validation rules so we have nothing to du here
            if (empty($this->scheme['fields'])) {
                return $data;
            }

            // Use the fields list from existing scheme
            $fields = $this->scheme['fields'];
        }

        // Still no fields?
        if (empty($fields)) {
            return $data;
        }

        // Lets run our rules
        foreach ($data as $key => $val) {

            // Is this field inside the $skip array list?
            if (in_array($key, $skip)) {
                continue;
            }

            // Run possible filters before the validation process
            if ($filter_before_validate && !empty($fields[$key]['filter'])) {

                if (!is_array($fields[$key]['filter'])) {
                    $fields[$key]['filter'] = (array) $fields[$key]['filter'];
                }

                foreach ($fields[$key]['filter'] as $filter) {

                    $options = [];

                    if (is_array($filter)) {
                        $options = $filter[1];
                        $filter = $filter[0];
                    }

                    $result = filter_var($val, $filter, $options);

                    if ($result === false) {
                        $this->addError($key, sprintf($this->app->language->get('validator.filter'), $filter));
                    }
                    else {
                        $data[$key] = $result;
                    }
                }
            }

            if (empty($fields[$key]['validate'])) {
                continue;
            }

            if (empty($validator)) {
                $validator = new Validator();
            }

            if (!is_array($fields[$key]['validate'])) {
                $fields[$key]['validate'] = (array) $fields[$key]['validate'];
            }

            $validator->setValue($val);

            foreach ($fields[$key]['validate'] as $rule) {

                $validator->parseRule($rule);
                $validator->validate();

                if (!$validator->isValid()) {

                    $result = $validator->getResult();

                    if (is_array($result)) {
                        $result = vsprintf($this->app->language->get($result[0]), $result[1]);
                    }
                    else {
                        $result = $this->app->language->get($result);
                    }

                    $this->errors[$key][] = $result;
                }
            }
        }

        return $data;
    }
600529
public function validate(array $rules = [], array $messages = [], bool $merge = true) : bool
    {
        if ($merge) {
            $rules = array_merge($this->rules(), $rules);
            $messages = array_merge($this->defaultMessages, $this->messages(), $messages);
        }
        $rules = $this->uniqueUpdates($rules);
        $validation = LaravelValidator::make($this->input, $rules, $messages);
        if ($validation->fails()) {
            $this->validation = $validation;
            return false;
        } else {
            $this->validation = false;
            return true;
        }
    }
380120
public function validate($data)
    {
        $errors = new \Concrete\Core\Error\Error();

        /**
         * if ('Oliver' !== $data['name']) {
         *     $errors['name'] = "You input the incorrect name.";
         * }.
         */
        if ($errors->has()) {
            return $errors;
        }

        return true;
    }
416585
protected final function validateNewData(array $data = null) {
		if ($data === null && isset($this->_formData)) {
			$data = $this->_formData;
		}
		if ($this->rules) {
			return $this->validateData($this->rules, $data);
		}

		return true;
	}
1200189
public function validate(array $values, array &$errorsList): bool
    {
        $hasErrors = false;
        foreach ($this->data as $item) {
            $type = $item[0];
            $errorMessage = $item[1];
            $elementName = $item[2];
            $value = isset($values[$elementName]) ? (string) $values[$elementName] : '';
            $hasError = false;
            if ($type === 'required') {
                if (strlen($value) === 0) {
                    $hasError = true;
                }
            } elseif ($type === 'minLength') {
                if (strlen($value) < $item[3]) {
                    $hasError = true;
                }
            } elseif ($type === 'maxLength') {
                if (strlen($value) > $item[3]) {
                    $hasError = true;
                }
            } elseif ($type === 'email') {
                if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                    $hasError = true;
                }
            } elseif ($type === 'regExp') {
                if (!filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => $item[3]]])) {
                    $hasError = true;
                }
            }
            if ($hasError) {
                $errorsList[] = [
                    'elementName' => $elementName,
                    'errorMessage' => $errorMessage
                ];
                $hasErrors = true;
            }
        }
        return !$hasErrors;
    }
271970
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if((!$exists || \is_null($value) || (\is_string($value) === true && \trim($value) === '')) && (!isset($_FILES[$key]) || $_FILES[$key]['error'] != 0)) {
            return 'formvalidator_make_required';
        }
        
        return true;
    }
1302847
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(isset($_FILES[$key]) && \file_exists($_FILES[$key]['tmp_name']) && $_FILES[$key]['error'] == 0) {
            $v = \round((\filesize($_FILES[$key]['tmp_name']) / 1024));
        } else {
            if(!$exists) {
                return false;
            }
            
            if(\is_array($value)) {
                $v = \count($value);
            } elseif(\is_numeric($value)) {
                $v = $value;
            } else {
                $v = \mb_strlen($value);
            }
        }
        
        if($v < $options) {
            if(\is_string($value)) {
                return array('formvalidator_make_min_string', array('{0}' => $options));
            } else {
                return array('formvalidator_make_min', array('{0}' => $options));
            }
            
        }
        
        return true;
    }
293703
final public function validate($data)
    {
        if ($this->_walk && (is_array($data) || is_object($data))) {
            $arr = (array)$data;

            foreach ($arr as $value) {
                if ($this->validate($value) ===  false) {
                    return false;
                }
            }
        } else {
            $context = $this->_chain->getContext();
            $context->data = $data;

            $result = $this->_chain->run('validate', $context);

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

        return true;
    }
955264
public function validate()
    {
        # addValues adds validation errors for unknown values
        $errs = count($this->errors);

        $dataKey = constant(get_called_class()."::EVENT_DATA_KEY");

        if ($this->beforeValidate() !== true) {
            return false;
        }
        foreach ($this->fields as $field) {
            if ($field->validate($this) === false) {
                foreach ($field->getErrors() as $error) {
                    $this->addError($error);
                    $errs++;
                }
            }
        }
        return (
            $errs > 0 ||
            $this->afterValidate() !== true ||
            count($this->errors) > 0
        ) ? false : true;
    }
151048
public function validate($fields = [])
    {
        if (empty($this->rules())) return true;
        foreach ($this->rules() as $rules) {
            if (is_array($rules[0])) {
                foreach ($rules[0] as $v){
                    if(!empty($fields) && !in_array($v,$fields)) continue;
                    $this->_validate($rules,$v);
                }
            } else {
                if(!empty($fields) && !in_array($rules[0],$fields)) continue;
                $this->_validate($rules,$rules[0]);
            }
        }
        $attributes = $this->attributes();
        if(!empty($this->_validateError) && !empty($attributes)){
            foreach ($this->_validateError as $k=> &$v){
                if(strpos($v,':attribute')!==false){
                    $v = isset($attributes[$k])? str_replace(':attribute',$attributes[$k],$v) : $v;
                }
            }
        }
        return empty($this->_validateError);
    }
757086
public function validate() {
        // Deny if rules array is empty
        if (empty($this->rules))
            return true;
        // If rules are invalid
        if (!is_array($this->rules))
            throw new \Exception("The rules must be an array of the validator|sanitize rules", 1);
        // Loop the rules
        foreach ($this->rules as $rule) {
            // Run rule
            $rule instanceof \Closure
                ? $rule($this)
                : call_user_func($rule, $this);
        }
        // Check the field is valid
        return !$this->hasError();
    }
869
private function check_fields(array $data)
    {
        $ruleset = $this->validation_rules();
        $mismatch = array_diff_key($data, $ruleset);
        $fields = array_keys($mismatch);

        foreach ($fields as $field) {
            $this->errors[] = array(
                'field' => $field,
                'value' => $data[$field],
                'rule' => 'mismatch',
                'param' => null,
            );
        }
    }
1341975
public function validate(array $options = array()) {
        $validated= false;
        if ($validator= $this->getValidator()) {
            $validated= $this->_validator->validate($options);
            if ($this->xpdo->getDebug() === true) {
                $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Validator class executed, result = " . print_r($validated, true));
            }
        } else {
            if ($this->xpdo->getDebug() === true) {
                $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "No validator found for {$this->_class} instance.");
            }
            $validated= true;
        }
        return $validated;
    }
303236
public function validate(Validation $validation, $field) : bool
    {
        if (!is_string($field)) {
            throw new Exception(
                "Field name must be a string"
            );
        }



        $label = $this->getOption("label");

        if (empty($label)) {
            $label = $validation->getLabel($field);
        }



        $value = $validation->getValue($field);

        if ($this->isSetOption("allowEmpty") && empty($value)) {
            return true;
        }



        $uuidRegEx = "/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[1-5][A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/i";

        if (!preg_match($uuidRegEx, $value)) {
            $message = $this->getOption("message");

            if (empty($message)) {
                $message = "Field :field must be a valid UUID";
            }



            $replacePairs = [
                ":field" => $label,
            ];

            $validation->appendMessage(
                new Message(
                    strtr($message, $replacePairs),
                    $field,
                    "Uuid"
                )
            );

            return false;
        }



        $allowedVersions = $this->getOption("allowedVersions");

        if (empty($allowedVersions)) {
            $allowedVersions = [1, 2, 3, 4, 5];
        }



        if (!in_array(substr($value, 14, 1), $allowedVersions)) {
            $message = $this->getOption("messageVersion");

            if (empty($message)) {
                $message = "Field :field must be one of the following UUID versions: :versions";
            }



            $replacePairs = [
                ":field" => $label,
                ":versions" => implode(", ", $allowedVersions),
            ];

            $validation->appendMessage(
                new Message(
                    strtr($message, $replacePairs),
                    $field,
                    "Uuid"
                )
            );

            return false;
        }

        return true;
    }
835910
public static function isValid($validation, $fieldname) {
    // No validation means you dont want to validate, so return affirmative.
    if (!$validation) {
      return true;
    }

    // Get filename.
    $filename = explode(".", $_FILES[$fieldname]["name"]);

    // Validate uploaded files.
    // Do not use $_FILES["file"]["type"] as it can be easily forged.
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimeType = self::getMimeType($_FILES[$fieldname]["tmp_name"]);

    // Validation is a function provided by the user.
    if ($validation instanceof \Closure) {
        return $validation($_FILES[$fieldname]["tmp_name"], $mimeType);
    }

    if (is_array($validation)) {
      return self::isFileValid($filename, $mimeType, $validation['allowedExts'], $validation['allowedMimeTypes']);
    }

    // Else: no specific validating behaviour found.
    return false;
  }
973785
public function validate($rules = array()) {
        if (empty($rules)) {
            $rules = $this->rules();
        }
        if ($this->validateAttribute($rules)) {
            return true;
        }
        Factory::log()->error('model validate error', $this->getError());
        return false;
    }
598353
public function isValid($value, array $fields = []): bool
    {
        $callback = new Callback($this->validation);
        $arguments = $this->getFunctionArguments($callback->getReflection(), $value, $fields);
        return $callback->executeArray($arguments);
    }