Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

TK Entry - Validating Input

by Dirk80 (Monk)
on Mar 06, 2013 at 13:53 UTC ( #1022011=perlquestion: print w/ replies, xml ) Need Help??
Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:


I want to validate the input of an entry widget. Only positive hexadecimal digits shall be allowed.

Here my code:

#!/usr/bin/perl use strict; use warnings; use Tk; use Data::Dumper; my $mw = new MainWindow; $mw->title ("Perl/Tk - Entry Valdiation"); my $entry1 = $mw->Entry ( '-width' => 30, '-validate' => 'key', '-validatecommand' => sub { print Dumper( \@_ ); + return 0 unless( $_[0] =~ m/^[0-9a-fA-F] ++/ ) } ); $entry1->pack(); MainLoop;

After the input of a valid character I can never remove it again. The first character is always there then. In the dumped output I can see that the character should be gone, but it is still visible in the entry.

Am I doing something wrong? Is it a bug?

Thanks alot for your help.



Comment on TK Entry - Validating Input
Download Code
Replies are listed 'Best First'.
Re: TK Entry - Validating Input
by Crackers2 (Parson) on Mar 06, 2013 at 14:49 UTC

    Your regex m/^[0-9a-fA-F]+/ doesn't match the empty string, so when you try to remove the last character your validation fails and the remove is disallowed.

    Try return 0 unless( $_[0] =~ m/^[0-9a-fA-F]*/ ) instead.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1022011]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2015-11-25 15:22 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (681 votes), past polls