Habari\FormValidators::validate_range PHP Метод

validate_range() публичный статический Метод

A validation function that returns an error if the value passed is not within a specified range
public static validate_range ( string $value, FormControl $control, FormContainer $container, float $min, float $max, string $warning = null ) : array
$value string A value to test if it is empty
$control FormControl The control that defines the value
$container FormContainer The container that holds the control
$min float The minimum value, inclusive
$max float The maximum value, inclusive
$warning string An optional error message
Результат array An empty array if the value is value, or an array with strings describing the errors
    public static function validate_range($value, $control, $container, $min, $max, $warning = null)
    {
        if ($value < $min) {
            if ($warning == null) {
                $warning = _t('The value entered for %s is lesser than the minimum of %d.', array($control->get_label(), $min));
            }
            return array($warning);
        } elseif ($value > $max) {
            if ($warning == null) {
                $warning = _t('The value entered for %s is greater than the maximum of %d.', array($control->get_label(), $max));
            }
            return array($warning);
        } else {
            return array();
        }
    }