Beispiel #1
0
 function validate()
 {
     $validator = new Validator($this->_value);
     if ($this->isRequired()) {
         $validator->required(sprintf("%s cannot be blank", $this->getName()));
     }
     $this->_errors = $validator->allErrors();
     return $this->allErrors();
 }
Beispiel #2
0
 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     if ($this->_max_length > -1) {
         $validator->maxLength($this->_max_length, sprintf("%s must not exceed %d characters", $this->getName(), $this->_max_length));
     }
     $this->_errors = array_merge($errors, $validator->allErrors());
     return $this->allErrors();
 }
Beispiel #3
0
 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     if (!$this->isMultiline()) {
         $validator->notRegexp("/\n/", sprintf("%s must be only one line", $this->getName()));
     }
     $this->_errors = array_merge($errors, $validator->allErrors());
     return $this->allErrors();
 }
Beispiel #4
0
 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     $validator->date(sprintf("%s is not a date", $this->getName()));
     if ($this->_min_value) {
         $validator->minDate(sprintf("%s is too small", $this->getName()));
     }
     if ($this->_max_value) {
         $validator->maxDate(sprintf("%s is too big", $this->getName()));
     }
     if ($validator->hasErrors()) {
         $this->_errors = array_merge($errors, $validator->allErrors());
     }
     return $this->allErrors();
 }
Beispiel #5
0
 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     if ($this->_decimal) {
         $validator->float(sprintf("%s must be a number", $this->getName()));
     } else {
         $validator->integer(sprintf("%s must be a number", $this->getName()));
     }
     if ($this->_min_value) {
         $validator->min($this->_min_value, sprintf("%s must be greater than %f", $this->getName(), $this->_min_value));
     }
     if ($this->_max_value) {
         $validator->max($this->_max_value, sprintf("%s must be less than %f", $this->getName(), $this->_max_value));
     }
     $this->_errors = array_merge($errors, $validator->allErrors());
     return $this->allErrors();
 }
Beispiel #6
0
 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     if (is_array($data) && !$this->isMultiple()) {
         $errors[] = sprintf("only choose one value for %s", $this->getName());
     } elseif (is_array($data) && $this->isMultiple()) {
         foreach ($data as $item) {
             $validator->setValue($item);
             $validator->oneOf($this->getChoices(), sprintf("'%s' is an unknown choice for %s", $item, $this->getName()));
         }
     } else {
         $validator->oneOf($this->getChoices(), sprintf("'%s' is an unknown choice for %s", $item, $this->getName()));
     }
     if ($validator->hasErrors()) {
         $this->_errors = array_merge($errors, $validator->allErrors());
     }
     return $this->allErrors();
 }