think\Validate::length PHP Method

length() protected method

验证数据长度
protected length ( mixed $value, mixed $rule ) : boolean
$value mixed 字段值
$rule mixed 验证规则
return boolean
    protected function length($value, $rule)
    {
        if (is_array($value)) {
            $length = count($value);
        } elseif ($value instanceof File) {
            $length = $value->getSize();
        } else {
            $length = mb_strlen((string) $value);
        }
        if (strpos($rule, ',')) {
            // 长度区间
            list($min, $max) = explode(',', $rule);
            return $length >= $min && $length <= $max;
        } else {
            // 指定长度
            return $length == $rule;
        }
    }