예제 #1
0
 public function check()
 {
     $l = mb_strlen($this->_data);
     if ($this->required && !$l) {
         $this->postError('invalid', self::$errorCodes['invalid']);
         return;
     }
     if ($this->pattern !== null && !preg_match($this->pattern, $this->_data)) {
         $this->postError('invalidPattern', self::$errorCodes['invalidPattern']);
         return;
     }
     if ($this->type == self::TYPE_EMAIL && !StringTools::isEmailAddress($this->_data)) {
         $this->postError('invalidEmail', self::$errorCodes['invalidEmail']);
         return;
     } else {
         if ($this->type == self::TYPE_URL && !StringTools::isUrl($this->_data)) {
             $this->postError('invalidUrl', self::$errorCodes['invalidUrl']);
             return;
         }
     }
     if ($this->minLength || $this->maxLength) {
         $code = $length = null;
         if ($this->minLength && $l < $this->minLength) {
             $code = 'minLength';
             $length = $this->minLength;
         } elseif ($this->maxLength && $l > $this->maxLength) {
             $code = 'maxLength';
             $length = $this->maxLength;
         }
         if ($code) {
             $this->postError($code, self::$errorCodes[$code], array('%length%' => $length));
             return;
         }
     }
 }
예제 #2
0
 public function isValid($value)
 {
     return StringTools::isUrl($value);
 }