in reply to Re^2: Stopping bad input (harder than sanitizing)
in thread Stopping bad input (harder than sanitizing)

You could use a character class to accept : and - in the validatecommand sub.

'-validatecommand' => sub {$_[1] =~/[\w:-]+/ ;} ,

WRT your invalidcommand sub, the regexp does nothing at the moment. Should the first line be something like this if you want to accept control characters?

'-invalidcommand' => sub { return if $_[1] =~/^[[:cntrl:]] ; $top -> bell; }

Or do you want the bell if it starts with a control character?

'-invalidcommand' => sub { $top -> bell if $_[1] =~/^[[:cntrl:]] ; }

I don't code with Tk, but hopefully this is useful.

Replies are listed 'Best First'.
Re^4: Stopping bad input (harder than sanitizing)
by Anonymous Monk on Mar 10, 2021 at 18:11 UTC

    Here is something new: I also wanna catch '[' (for [(1)). But when my expression is $_1 =~ /^[\w\s:-\[]+/ it spits out an error and says "stack moved" (is that PERL humor?). How do I add '[' to the character class? When I press <RET> with no data, the program still locks up.

      The hyphen in the middle is significant. Move it to the end if you want it to be a literal.


      🦛

      Please put perl code inside code tags, it's not possible to tell just what you entered.

Re^4: Stopping bad input (harder than sanitizing)
by Anonymous Monk on Mar 10, 2021 at 17:42 UTC

    Gonna try those two ideas right now. My goal is two fold: 1) if this character-set, then its valid 2) if it begins with a control char (in particular <RET> ) then complain