Ejemplo n.º 1
0
 public function isValid($value)
 {
     $value = (string) $value;
     $valid = TRUE;
     if (trim($value) != '') {
         if ($this->minLength != -1) {
             if (strlen($value) < $this->minLength) {
                 $this->addMessage('minLength');
                 $valid = FALSE;
             }
         }
         if ($this->maxLength != -1) {
             if (strlen($value) > $this->maxLength) {
                 $valid = FALSE;
                 $this->addMessage('maxLength');
             }
         }
         if ($this->regexp) {
             $status = @preg_match($this->regexp, $value);
             if ($status === FALSE) {
                 $this->addMessage('regexp');
                 $valid = FALSE;
             }
         }
         if (!$this->allowHtml && self::containsHtml($value)) {
             $this->addMessage('noHtml');
             $valid = FALSE;
         }
     }
     return parent::isValid($value) && $valid;
 }
Ejemplo n.º 2
0
 public function isValid($value)
 {
     $value = (string) $value;
     $valid = TRUE;
     if (trim($value) != '') {
         if (count($this->allowedValues)) {
             $valid = FALSE;
             foreach ($this->allowedValues as $allowed) {
                 // cast both to string
                 if ("{$value}" == "{$allowed}") {
                     $valid = TRUE;
                 }
             }
             if (!$valid) {
                 $this->addMessage('inList');
             }
         }
     }
     return parent::isValid($value) && $valid;
 }