Ensure that the field counts match the validation rule counts.

@param array $data
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,
            );
        }
    }
763150
protected function validate(array $data, array $rules = null): void
    {
        $validator = $this->validatorFactory->make($data, $rules ?? $this->getValidationRules());
        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
    }
703305
public function validate($context = 'default', array $data = [])
    {
        if (!empty($data)) {
            $this->setData($data);
        }

        $this->setContext($context);
        $rules = $this->buildRulesArray();
        $validator = $this->factory->make($this->filterArray($rules, $this->data), $rules);
        if ($validator->passes()) {
            return $validator->getData();
        }
        throw new ValidationException($validator);
    }
509755
private function tryValidateData(
        array $data,
        array $rules,
        Closure $validationFailed,
        array $messages = [],
        array $customAttributes = []
    ) {
        $validator = $this->createValidator($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            call_user_func($validationFailed, $validator->errors()->getMessages());
        }
    }
24494
public function isValid($data) {
        if (!is_array($data)) {
            throw new Zend_Form_Exception(__METHOD__ . ' expects an array');
        }

        $this->_incrementArray($data);
        return parent::isValid($data);
    }
260364
protected function afterValidation($data)
  {
    if ($this->after_validation) {
      $data = call_user_func_array($this->after_validation, array($data, $this));
    }

    return $data;
  }
539889
protected function validate(array &$data)
    {
        $this->validateVersion();
        $this->validateExtensions();
        $this->validateIni();
        $data = array_merge($data, ['messages' => $this->messages]);
        return $data;
    }
692772
protected function validate(array $data, array $rules)
    {
        $validator = $this->validator->make($data, $rules);
        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
        return $this;
    }
354139
public function update(array $data)
    {
        try
        {
            if ($this->validator->with($data)->validForUpdate())
            {
                $this->groups->update($data);
                return true;
            }
        }
        catch (GroupExistsException $e)
        {
            $this->validator->add('GroupExistsException', $e->getMessage());
        }
        catch (NameRequiredException $e)
        {
            $this->validator->add('NameRequiredException', $e->getMessage());
        }

        return false;
    }
572879
public function val(array $data)
    {
        $this->_fields = $data;
        $labels = array();
        foreach ($data as $key => $value) {
            $labels[$key] = ucwords(str_replace('_', ' ', $key));
        }
        
        $this->labels($labels);
        
        return parent::validate();
    }
205743
public function validate( array $data ) {
		// Validate use Validator.
		try {
			$this->validate_use_validator( $data, $this->get_validate_rules() );
		} catch ( \Exception $e ) {
			trigger_error( $e->getMessage(), E_USER_WARNING ); // @WPCS: XSS OK.
		}

		// Validate use custom callback.
		$callbacks = $this->fields->pluck( 'validate_cb', 'id' )->filter( 'is_callable' );

		if ( $callbacks->isNotEmpty() ) {
			$this->validate_by_callbacks( $data, $callbacks->all() );
		}
	}
1208989
private function validate($data)
    {
        // null or zero-length values cannot be assigned references
        if (is_null($data) || (is_string($data) && !strlen($data))) {
            return false;
        }

        return true;
    }
31488
public function check(array $data, array $messages = array())
    {

        // Merge the given messages with the set messages.
        $messages = array_merge($this->_messages, $messages);

        // Check the CSRF token if we have a session object
        if ($this->_session) {

            if (!isset($data['_token']) || $data['_token'] !== $this->_session->getToken()) {

                $this->_errors[] = $messages['csrf'];
                return false;

            }

        }

        // Loop all the set rules and validate
        foreach ($this->_rules as $key => $rules)
        {
            // If the rules are a string, break it apart
            if (is_string($rules))
                $rules = explode('|', $rules);

            // Get the data for the rule
            $input = isset($data[$key]) ? $data[$key] : null;

            // Get the type of the input
            $inputType = $this->getInputType($input);

            // Create a key for messages
            $m_key = str_replace(array('_', '-'), ' ', $key);

            // Loop through each rule and validate
            foreach($rules as $rule) {

                // Turn the rule into an array and explode if it has parameters
                $rule = strpos($rule, ':') !== false ? explode(':', $rule) : array($rule);

                // If the rule is "required", it's a built in rule
                if ($rule[0] == 'required') {

                    if (!$input || empty($input)) {

                        if (isset($messages['required.'.$key])) {
                            $message = $messages['required.'.$key];
                        } else {
                            $message = str_replace(':key', $m_key, $messages['required']);
                        }

                        $this->_errors[] = $message;

                        break;

                    }

                    continue;

                }

                // If it's not a required field we have been given null, skip it
                if (!$input || empty($input))
                    break;

                // Throw an error if we don't have a handler for the rule
                if (!isset(static::$_handlers[$rule[0]]))
                    continue;
                //throw new \Exception('m\Validator: "'.$rule[0].'" is not a valid rule.  No matching handler exists.');

                // Handle lazy loaded handlers
                if (!is_object(static::$_handlers[$rule[0]])) {
                    $handlerName = static::$_handlers[$rule[0]];
                    $handler = new $handlerName();
                    static::$_handlers[$rule[0]] = $handler;
                } else {
                    $handler = static::$_handlers[$rule[0]];
                }

                // If there are parameters, turn them into an array
                $params = (isset($rule[1])) ? explode(',', $rule[1]) : array();

                // Add the input field to the front of the params array
                array_unshift($params, $input);

                // Call the handler and pass it the parameters
                $result = call_user_func_array(array($handler, 'check'.ucfirst($inputType)), $params);

                // If the check failed, log an error and stop validating this field
                if ($result === false) {

                    // Shorthand message keys
                    $ruleFieldName      = $rule[0].'.'.$key;
                    $ruleTypeName       = $rule[0].'.'.$inputType;

                    // Determine which message is available to send
                    if (isset($messages[$ruleFieldName])) {
                        $message = $messages[$ruleFieldName];
                    } elseif (isset($messages[$ruleTypeName])) {
                        $message = $messages[$ruleTypeName];
                    } elseif (isset($messages[$rule[0]])) {
                        $message = $messages[$rule[0]];
                    } else {
                        $message = 'The :key field failed to validate.';
                    }

                    array_shift($params);

                    // Format and log the message
                    $this->_errors[] = $handler->formatMessage($message, $m_key, $params);

                    // Onto the next field
                    break;
                }
            }
        }

        // If we have errors, we failed...
        return count($this->_errors) > 0 ? false : true;
    }
308720
public function validate(array $data)
    {
        $errors = [];

        if (empty($data['name'])) {
            $errors[] = ['path' => '/name', 'message' => 'name can not be empty.'];
        }

        if (empty($data['type'])) {
            $errors[] = ['path' => '/type', 'message' => 'type can not be empty.'];
        }

        if (empty($data['scheduledDate'])) {
            $errors[] = ['path' => '/scheduledDate', 'message' => 'scheduledDate can not be empty.'];
        }

        return $errors;
    }
1152954
public function is_valid(array $data) {

		$this->data = $this->apply_filters($data);

		$this->errors = $this->test_rules();

		return empty($this->errors);

	}
1372806
public function validates($data = null)
    {
        $this->errors = array();

        // Get data if it wasn't passed
        if ($data === null) {
            $data = $this->data();
        }

        foreach (static::$_validates as $field => $validations) {
            Validations::run($this, $field, $validations);
        }

        return count($this->errors) == 0;
    }
700700
public function validateResponseData($data)
    {
        if (!isset($data->status)) {
            throw EventValidationResponseCorruptDataException::eventApiResponseCorrupt($data);
        } elseif (isset($data->errors)) {
            throw EventValidationResponseErrorException::eventApiResponseError($data->errors[0]);
        }
    }