in reply to Changing the Textvariable of a restricted entry widget (TK)

I'm not really up on Tk programming, but that validate command sub looks fishy. ;-)

-validatecommand => sub { $_[1] =~ /^[aAdDtTsSoOuU]*$/; },

Comments:

  1. Whitespace is your friend. Use some. ;-)
  2. Check out the perlre document on how regular expressions work. You don't list the characters in quotes, separated by commas. Think of regular expressions as an entirely separate language from perl. It really is. Mostly.
  3. You want to check that the entire string is made up of only DATSOU letters - so you need to match the whole string. ^ matches the beginning, $ matches the end. The string in between is made up of zero or more (specified by the *) of the characters in the brackets.
  4. You can also use /[datsou]/i - the i at the end says this is case insensitive. It is also usually slower, but it's more readable. This would be the way I'd usually go myself, but I also wanted to show you code that was as close to what you already had as I could.
  5. Hope that helps.

Replies are listed 'Best First'.
Re^2: Changing the Textvariable of a restricted entry widget (TK)
by pg (Canon) on Aug 03, 2005 at 04:47 UTC

    His validate command sub is fine. the validatecommand sub takes several args, and the second one is the char being added or deleted. It is just one char, whether use ^ and $ is not important here.