NAME

TRangeValidator - integer range validator for numeric input

HIERARCHY

TObject
  TValidator
    TFilterValidator
      TRangeValidator

SYNOPSIS

use TUI::Validate::RangeValidator;

my $vUnsigned = new_TRangeValidator( 1, 100 );

if ( $vUnsigned->isValid($input) ) {
  # integer string is in range
}

my $vSigned = TRangeValidator->new( min => -10, max => 10 );

DESCRIPTION

TRangeValidator validates integer text input against an inclusive minimum and maximum bound. It inherits character filtering behavior from TFilterValidator and then applies a numeric range check in isValid.

At construction time, the module configures the accepted character set from the selected range: non-negative ranges allow +0123456789, while ranges that include negative numbers allow +-0123456789.

Commonly Used Features

Typical usage is to create a validator with min and max, assign it to an input field, and let the framework call isValidInput while typing and isValid on commit. If the committed value is outside the configured range, error shows a formatted message with both limits.

VARIABLES

$errorMsg

our $errorMsg = "Value not in the range %d to %d";

Package-global error template used by error(). The placeholders receive the current min and max values.

$validUnsignedChars

our $validUnsignedChars = "+0123456789";

Character set applied when min is non-negative.

$validSignedChars

our $validSignedChars = "+-0123456789";

Character set applied when min is negative.

ATTRIBUTES

min

Inclusive lower bound for accepted integer values (read-only).

max

Inclusive upper bound for accepted integer values (read-only).

CONSTRUCTOR

new

my $v = TRangeValidator->new( min => $min, max => $max );

Creates a range validator with mandatory bounds. min must be less than or equal to max; otherwise construction fails an assertion in BUILD.

new_TRangeValidator

my $v = new_TRangeValidator( $aMin, $aMax );

Convenience factory with positional arguments. Exported by default.

METHODS

error

$v->error();

Displays a modal error message using $errorMsg, formatted with the current minimum and maximum bounds.

isValid

my $ok = $v->isValid( $s );

Returns true only when all of the following are true:

  • the input passes the inherited character filter,

  • the input matches an integer literal [+-]?\d+,

  • the parsed integer is between min and max (inclusive).

Otherwise it returns false.

transfer

my $ok = $v->transfer( $s, $buffer, $flag );

Transfers numeric data between the field string and an external buffer when the validator option voTransfer is enabled.

For vtGetData, it parses $s as an integer and writes the number to the buffer slot. For vtSetData, it formats the provided buffer value back into the field string.

Returns 1 on successful transfer and 0 otherwise.

SEE ALSO

TFilterValidator, TValidator, TUI::Validate::Const

AUTHORS

  • Borland International (original Turbo Vision design)

  • J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)

COPYRIGHT AND LICENSE

Copyright (c) 1990-1994, 1997 by Borland International

Copyright (c) 2026 the "AUTHORS" as listed above.

This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).