Checks if the passed value is valid.

@param mixed $value      The value that should be validated
@param Date  $constraint The constraint for the validation

@api
196832
public function validate($value, Constraint $constraint)
  {
    $valid = false;
    foreach ($constraint->format as $format)
    {
      $date = \DateTime::createFromFormat($format, $value);
      if ($date instanceof \DateTime)
      {
        $valid = true;
        break;
      }
    }
    if ($valid === false)
    {
      $this->context->addViolation($constraint->message, array('%invalid%' => $value));
    }
  }
666898
public function validate($value, Constraint $constraint)
    {
        /** @var EntityExists $constraint */
        if ($constraint->validate($value)) {
            $this->context->addViolation(
                $constraint->message,
                [
                    '{{ type }}' => $constraint->entityClass,
                    '{{ value }}' => $value,
                ]
            );
        }
    }
687611
protected function validate_duedate($value) {

        // During update.
        if ($this->get('id')) {
            $before = $this->beforeupdate->get('duedate');

            // The value has not changed, then it's always OK.
            if ($before == $value) {
                return true;
            }
        }

        // During create and update, the date must be set in the future, or not set.
        if (!empty($value) && $value <= time() - 600) {
            // We cannot set the date in the past. But we allow for 10 minutes of margin so that
            // a user can set the due date to "now" without risking to hit a validation error.
            return new lang_string('errorcannotsetduedateinthepast', 'core_competency');
        }

        return true;
    }
412022
public function validate($value, Constraint $constraint)
    {
        if (!$value instanceof SectionUpdateData) {
            return;
        }

        try {
            $section = $this->sectionService->loadSectionByIdentifier($value->identifier);
            if ($section->id == $value->getId()) {
                return;
            }

            $this->context->buildViolation($constraint->message)
                ->atPath('identifier')
                ->setParameter('%identifier%', $value->identifier)
                ->addViolation();
        } catch (NotFoundException $e) {
            // Do nothing
        }
    }
162104
protected function validateDelimiter(Constraint $constraint)
    {
        if (strlen($constraint->delimiter) > 2) {
            throw new ConstraintDefinitionException(sprintf('"%s" is not a valid delimiter', $constraint->delimiter));
        }
    }
1330059
public function validate($value, Constraint $constraint): void
    {
        if ($value !== null) {
            $type = $constraint->type;
            $values = $type::getValues();
            if (!\in_array($value, $values, true)) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ type }}', $constraint->type)
                    ->setParameter('{{ value }}', $value)
                    ->addViolation();
            }
        }
    }
1146590
public function validate($propertyValue, Constraint $constraint)
    {
        // Implement your validation logic.
        // Return early if the value is valid
        // For example:
        if ($propertyValue === 'isValid') {
            return;
        }

        // Finally, if not valid, add the violation
        $this->context->buildViolation($constraint->message)
                      ->setParameter('{{ string }}', $propertyValue)
                      ->addViolation();
    }
876970
public function checkDate($value)
    {

        if ($value instanceof PointInTimeContract) {
            return $value->isValid();
        }

        if ($value instanceof DateTimeInterface) {
            return true;
        }

        // Support for legacy datetime objects like Zend_Date
        if (is_object($value) && method_exists($value, 'getTimestamp')) {
            return $this->checkInt($value->getTimestamp());
        }

        if ((!Type::isStringLike($value) && !is_numeric($value)) || strtotime($value) === false) {
            return false;
        }

        $date = date_parse($value);

        return checkdate($date['month'], $date['day'], $date['year']);
    }
427188
public function validate($value, Constraint $constraint)
    {
        $block = $constraint->block;
        if ($block instanceof BlockInterface && true === $block->isTransverse() && !empty($value)) {
            $blockCode = $this->repository->findOneTransverseBlockByCode($value, $block->getLanguage(), $block->getSiteId());
            if (null !== $blockCode && $blockCode->getId() !== $block->getId()) {
                $this->context->buildViolation($constraint->message)
                    ->atPath('code')
                    ->addViolation();
            }
        }

    }
966944
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Bsn) {
            throw new UnexpectedTypeException($constraint, Bsn::class);
        }

        if (null === $value || '' === $value) {
            return;
        }

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedTypeException($value, 'string');
        }

        $value = (string) $value;

        if ('000000000' !== $value && preg_match('/^\d{9}$/', $value)) {
            list($a, $b, $c, $d, $e, $f, $g, $h, $i) = str_split($value);

            $sum = (9 * $a) + (8 * $b) + (7 * $c) + (6 * $d) + (5 * $e) + (4 * $f) + (3 * $g) + (2 * $h) + (-1 * $i);

            if (0 === $sum % 11) {
                return;
            }
        }

        $this->context->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->addViolation();
    }
270178
public function validate($value)
    {
        $date = \DateTime::createFromFormat($this->specification, $value);

        return $date !== false;
    }
1224966
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Luhn) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Luhn');
        }

        if (null === $value || '' === $value) {
            return;
        }

        // Work with strings only, because long numbers are represented as floats
        // internally and don't work with strlen()
        if (!\is_string($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if (!ctype_digit($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Luhn::INVALID_CHARACTERS_ERROR)
                ->addViolation();

            return;
        }

        $checkSum = 0;
        $length = \strlen($value);

        // Starting with the last digit and walking left, add every second
        // digit to the check sum
        // e.g. 7  9  9  2  7  3  9  8  7  1  3
        //      ^     ^     ^     ^     ^     ^
        //    = 7  +  9  +  7  +  9  +  7  +  3
        for ($i = $length - 1; $i >= 0; $i -= 2) {
            $checkSum += $value[$i];
        }

        // Starting with the second last digit and walking left, double every
        // second digit and add it to the check sum
        // For doubles greater than 9, sum the individual digits
        // e.g. 7  9  9  2  7  3  9  8  7  1  3
        //         ^     ^     ^     ^     ^
        //    =    1+8 + 4  +  6  +  1+6 + 2
        for ($i = $length - 2; $i >= 0; $i -= 2) {
            $checkSum += array_sum(str_split($value[$i] * 2));
        }

        if (0 === $checkSum || 0 !== $checkSum % 10) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Luhn::CHECKSUM_FAILED_ERROR)
                ->addViolation();
        }
    }
946670
public function validate($value, Constraint $constraint)
    {
        if ('' !== $value->getRoutePattern()
            && $this->repository->countByPattern($value->getRoutePattern(), $value->getId()) > 0
        ) {
            $this->context
                ->buildViolation($constraint->message)
                ->atPath('route_pattern')
                ->addViolation();
        }
    }
174498
public function validate($value, Constraint $constraint)
    {
        if (null === $value || '' === $value) {
            return;
        }

        if (!is_numeric($value)) {
            $this->context->addViolation($constraint->message);
        }

        $schemes = array_flip($constraint->schemes);
        $schemeRegexes = array_intersect_key($this->schemes, $schemes);

        $valid = false;
        foreach ($schemeRegexes as $regexes) {
            foreach ($regexes as $regex) {
                $valid |= preg_match($regex, $value);
            }
        }

        if (!$valid) {
            $this->context->addViolation($constraint->message);
        }
    }
1015620
public function validate($value, Constraint $constraint)
    {
        if($value instanceof SubscriberInterface) {
            if($this->manager->exists($value, $value->getType())) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('%email%', $value->getEmail())
                    ->addViolation();
            }
        }
    }
800840
protected function checkValue(): void
    {
        if ((!is_string($this->value) && !is_numeric($this->value)) || strtotime($this->value) === false) {
            throw new InvalidArgumentException('DateParser: Value must be a valid date');
        }
    }
79959
public function validate($value, Constraint $constraint)
    {
        /**@var $constraint CodeUnit */
        if (!in_array($value, $this->codes)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $value)
                ->addViolation();
        }
    }