Example #1
0
 /**
  * Validates the given data against this constraint. If the constraint was
  * already triggered before, then it will return the last result.
  *
  * @param mixed $data The data
  *
  * @return boolean
  */
 public function validate(Field $field, $data)
 {
     if (true === $this->checked) {
         return;
     }
     $this->checked = true;
     if (true === $this->check($data)) {
         return;
     }
     $field->addError(new Error($field->getInternalName(), $this->getMessage()));
 }
 public function validate(Field $field)
 {
     $l = strlen($field->getValue());
     if ($l < $this->min) {
         return $field->addError(sprintf($this->too_short, $field->getName(), $this->min));
     } elseif ($l > $this->max) {
         return $field->addError(sprintf($this->too_long, $field->getName(), $this->max));
     }
 }