yii\validators\StringValidator::validateValue PHP Method

validateValue() protected method

protected validateValue ( $value )
    protected function validateValue($value)
    {
        if (!is_string($value)) {
            return [$this->message, []];
        }
        $length = mb_strlen($value, $this->encoding);
        if ($this->min !== null && $length < $this->min) {
            return [$this->tooShort, ['min' => $this->min]];
        }
        if ($this->max !== null && $length > $this->max) {
            return [$this->tooLong, ['max' => $this->max]];
        }
        if ($this->length !== null && $length !== $this->length) {
            return [$this->notEqual, ['length' => $this->length]];
        }
        return null;
    }

Usage Example

 /**
  * @inheritdoc
  */
 protected function validateValue($value)
 {
     if ($res = parent::validateValue($value)) {
         return $res;
     }
     if ($res = $this->validateValueByPattern($value)) {
         return $res;
     }
     return null;
 }