Webiny\Component\Validation\Validators\MaxLength::validate PHP Method

validate() public method

public validate ( $value, $params = [], $throw = false )
    public function validate($value, $params = [], $throw = false)
    {
        $limit = $params[0];
        $length = is_string($value) ? strlen($value) : count($value);
        if ($length <= $limit) {
            return true;
        }
        if ($value < $limit) {
            return true;
        }
        $message = 'Value must contain %s characters at most';
        if ($throw) {
            throw new ValidationException($message, $limit);
        }
        return sprintf($message, $limit);
    }