The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tk::EntryCheck - Interface to Tk::Entry for controlling its maximum length and content in an easy way.

SYNOPSIS

  use Tk;
  use Tk::EntryCheck;

  my $mw = MainWindow->new();

  my $entry = $mw->EntryCheck(

    # some standard Entry-Options which are forwarded to Tk::Entry
    -width => 20,

    # and now the new options
    -maxlength => 10,     # accepts 10 chars at maximum for content
    -pattern   => qr/\d/, # accepts only \d, nothing else
  )
  ->pack();

  MainLoop();

DESCRIPTION

This module acts as a little wrapper around Tk::Entry and adds an easy to use interface to -validate and -validatecommand for controlling length and content of an entry widget.

It's provides the following additional features:

x) Set a maximum length to this entry with the parameter -maxlenght. Gives a warning by carp if this is defined but not a positive integer. If the content is added by changing a variable attached as -textvariable, it also gives a warning with carp and denies the change.

x) Allow only certain characters inside this entry. You can submit it as a regular expression in the parameter -pattern, e.g.

  -pattern => qr/[A-Za-z0-9]/, # alphanumeric

  -pattern = qr/\d/,           # numbers only

  -pattern = qr/[A-Z ]/,       # capital characters and spaces

If the content is added by a variable attached to the widget as -textvariable, it also gives a warning with carp and denies the change.

ATTENTION: this character class check is done for each character and enhanced internally by *, so don't try to use something like -pattern = qr(\d+)>, because that would result in \d+* and give an error.

ATTENTION: don't forget to specify an empty space if you need it...

If you want to overwrite the methods used for validation, you can do so by just setting the original entry options -validate and/or -validatecommand...

Dependencies

x) Perl-Version >= 5.005

x) Tk and Tk::Entry must be installed and running

EXPORT

Nothing. As there is no need for exports and as I hate namespace pollution, I removed the Exporter...

SEE ALSO

See Tk::Entry for the other options, especially the options -validate and -validatecommand

See Tk::FilterEntry which is similar.

Differences between Tk::EntryCheck and Tk::FilterEntry

x) FilterEntry doesn't deny adding invalid chars or strings which are too long

x) EntryCheck just checks each char if it in a characterclass, whereas FilterEntry checks the whole content with a regular expression, so it is more helpful when checking for special formats

x) FilterEntry (v0.02) gives a warning if the field is empty

x) FilterEntry gives nice textcolors if the content of the textfield is invalid; but that just works when the widget leaves the focus (V0.02)

See http://www.fabiani.net/: My Homepage (in German)

See http://www.perl-community.de/: German Perl Forum

AUTHOR

Martin Fabiani (aka Strat), <martin@fabiani.net>

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Martin Fabiani

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.