Return the validated form of the value.

Returns null if the value could not be validated.

@since 0.1.11

@param mixed $value Value to validate.

@return mixed|ValidationError Validated value. ValidationError instance if validation failed.
336942
public function validate($value)
    {
        $result = parent::validate($value);
        return null === $result
            ? new EmailAddressValidationError($this)
            : $result;
    }
945257
public function validate($value)
  {
    $this->reset();

    $this->value = $value;

    $this->validateRequired();
    $this->validateFilters();

    return $this->isValid();
  }
691181
public function validateMessage($value)
  {
    if (is_string($value)) {
      $result = true;
    } elseif (is_object($value) && method_exists($value, "__toString")) {
      $result = true;
    } else {
      $result = false;
    }
    
    return $result;
  }
942828
private function getValue($value)
    {
        if (!is_string($value)) {
            return $value;
        }

        if ($value[0] != '%' || $value[strlen($value) - 1] != '%')  {
            return $value;
        }

        $parameter = trim($value, '%');
        if ($this->container->hasParameter($parameter)) {
            return $this->container->getParameter($parameter);
        }

        return $value;
    }
1236315
protected function validateNumber($value)
    {
        $return = new ValidateResult($value, false);

        if (is_string($value)) {
            //Replace comma with dot
            $value = str_replace(',', '.', $value);
        }

        //Apply all rules
        if (!is_numeric($value) || filter_var($value, FILTER_VALIDATE_FLOAT) === false) {
            //error
            $return->errorObject = new IncorrectParametersException([
                [
                    'type' => static::getType(),
                    'failure' => 'type'
                ]
            ]);
        } elseif ($this->maximum !== null
            && ($value > $this->maximum
                || ($this->exclusiveMaximum === true && $value >= $this->maximum)
            )
        ) {
            //error
            $return->errorObject = new IncorrectParametersException([
                [
                    'type' => static::getType(),
                    'failure' => 'maximum'
                ]
            ]);
        } elseif ($this->minimum !== null
            && ($value < $this->minimum
                || ($this->exclusiveMinimum === true && $value <= $this->minimum)
            )
        ) {
            //error
            $return->errorObject = new IncorrectParametersException([
                [
                    'type' => static::getType(),
                    'failure' => 'minimum'
                ]
            ]);
        } elseif ($this->multipleOf !== null
            && fmod((float)$value, (float)$this->multipleOf) != 0
        ) {
            //error
            $return->errorObject = new IncorrectParametersException([
                [
                    'type' => static::getType(),
                    'failure' => 'multipleOf'
                ]
            ]);
        } else {
            $return->errorObject = null;
            //Set status to success
            $return->status = true;
            //Type cast
            $return->value  = $this->cast($value);
        }

        return $return;
    }
1209659
public function validate($value)
    {
        $value = filter_var($value, FILTER_VALIDATE_EMAIL);
        if (false === $value) {
            throw FailedToValidate::fromValueForClass($value, static::class);
        }
        return $value;
    }
492192
public function validateValue($value) {
        $validationResultSet = new ValidationResultSet();
        foreach($this->validators as $validator) {
            $validationResultSet->add($validator->validate($value));
        }
        return $validationResultSet;
    }
677398
protected function _validate($value)
    {
        $ret = parent::_validate($value);

        if ($ret) {
            if (strlen($value) < self::$MIN_LENGTH) {
                $ret = false;
            }
        }

        return $ret;
    }
801741
public function validate($value) {
        if(!is_numeric($value)) {
            throw new DataType('value', 'number', $value);
        }
        
        if($value > $this->max) {
            return new ValidationResult(false, sprintf('Value has to be below %d', $this->max));
        }
        
        return new ValidationResult(true);
    }
923706
public function validate($value) {
        if($this->sanitizable->getRawValue()===$value) {
            return new ValidationResult(true);
        }
        
        return new ValidationResult(false, 'The given value contains illegal characters');
    }
336688
public function validate($value)
    {
        $value = trim($value);
        return ((string) $value === $this->sanitize($value));
    }
401059
public function validate($value) : Result
    {
        return array_reduce(
            $this->restrictions,
            function ($result, $restriction) use ($value) : Result {
                if ($result->isFatal()) {
                    return $result;
                }

                return $result->concat($restriction($value));
            },
            Result::success()
        );
    }
673842
public function valid($value)
    {

        foreach($this->getRules() as $index => $rule) {

            // check for required
            if (in_array($value, ['', null]) && !$this->hasRule('required')) {
                continue;
            }

            // extract params
            list($method, $params) = $rule;

            // If method is null, we use the index as the method name
            $method = is_null($method) ? $index : $method;

            // Build the params
            array_unshift($params, $value);

            // If it's a anonymous function
            if (!is_string($method) && is_callable($method)) {

                if (!call_user_func_array($method, $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }

            } else {// if it's a local method

                if (!method_exists($this, $method)) {
                    throw new \Exception('Method "'. $method .'" not found for validator : ' . $index);
                }

                if (!call_user_func_array([$this, $method], $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }
            }
        }

        return $this;
    }
1363813
public function value($value = null)
    {
        $element = clone $this;

        $element->value = $value;

        $element->applyValueToOptions();

        return $element;
    }
665890
public function validate($value) {
        if(filter_var($value, FILTER_VALIDATE_FLOAT, array('options' => array('decimal' => $this->decimal)))===false) {
            return new ValidationResult(false, 'Not a floating point value');
        }        
        return new ValidationResult(true);
    }
873849
public function validate($value) {
        if(!is_string($value)) {
            throw new DataType('value', 'string', $value);
        }
        
        if(!password_verify($value, $this->hash)) {
            return new ValidationResult(false, 'Wrong password');
        }        
        return new ValidationResult(true);
    }
851822
private static function toPlainValue($value)
    {
        if (is_string($value)) {
            $value = strip_tags($value);
            $value = html_entity_decode($value, ENT_QUOTES | ENT_XML1, 'UTF-8');
            $value = trim($value);

            return ($value === '') ? null : $value;
        }

        return $value;
    }