NAME

TUI::Validate::FilterValidator - character-set validator for input fields

HIERARCHY

TObject
  TValidator
    TFilterValidator

SYNOPSIS

use TUI::Validate::FilterValidator;

# allow only decimal digits
my $v = new_TFilterValidator( '[0-9]' );

if ( $v->isValid($input) ) {
  # all characters in $input are within the allowed set
}

# named-parameter form
my $v2 = TFilterValidator->new( validChars => '[A-Za-z]' );

DESCRIPTION

TFilterValidator validates text by comparing each character against a caller-supplied set of allowed characters. The set is expressed as a character-class pattern (without the surrounding [...] brackets if given as a raw list, or with them if given as a regex fragment).

The validator integrates with input widgets: isValidInput is called keystroke by keystroke while the user is editing, whereas isValid performs the final check when the field is committed. If the check fails, error displays a message box so the user knows what went wrong.

Commonly Used Features

The most common use is to create a validator with a character-class string and attach it to an input line. For digit-only fields the pattern '[0-9]' is sufficient. For alphanumeric fields use '[A-Za-z0-9]'. The validChars attribute is read-only after construction, so the allowed set cannot be changed at runtime.

VARIABLES

$errorMsg

our $errorMsg = "Invalid character in input";

Package-global message displayed by error(). Override it before constructing any validator if a different message is needed.

ATTRIBUTES

validChars (ro)

my $pattern = $v->validChars;

Read-only string (Str) holding the character-class pattern used to decide whether a character is acceptable. Set once at construction time via the validChars (or aliased aValidChars) constructor argument.

CONSTRUCTOR

new

my $v = TFilterValidator->new( validChars => $pattern );

Constructs a new filter validator. $pattern is a string that describes the accepted characters, e.g. '[0-9]' for digits or '[A-Za-z]' for letters. The argument is mandatory; omitting it raises an exception.

new_TFilterValidator

my $v = new_TFilterValidator( $pattern );

Convenience factory that accepts the character-class pattern as a single positional argument and delegates to new. Exported by default.

METHODS

DEMOLISH

# called automatically by the object system

Cleanup hook. Clears the validChars slot before the object is freed. Invoked automatically; do not call directly.

error

$v->error();

Displays a modal message box (error style with an OK button) using the text stored in $errorMsg. Called internally by the input framework when validation fails.

isValid

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

Returns true if every character in $string appears in the validChars pattern, false otherwise. Intended for the final validation pass when the user commits the field.

isValidInput

my $ok = $v->isValidInput( $string, $suppressFill );

Returns true if every character in $string is within the allowed set. Called keystroke by keystroke during editing. $suppressFill is accepted for interface compatibility but currently has no effect.

SEE ALSO

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).