Re: How to limit decimals with entry validate
From: shamil (shamild_at_hotmail.com)
Date: 02/28/05
- Next message: George Petasis: "Bug in Tk_HandleEvent stops tkdnd from working under unix..."
- Previous message: lvirden_at_gmail.com: "Re: is there a loadable Expect out there ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Feb 2005 12:01:20 -0800
I looked through the re_syntax manual page and was playing around
trying to figure out how to also limit the number of digits to the left
of the decimal. I wanted to limit them to a maximum of 3 and thought
[regexp {^[0-9]{0,3}*\.?[0-9]{0,2}$} %P] would work. Unfortunately the
{0,3} is causing problems. Any ideas?
Donald Arseneau wrote:
> shamild@hotmail.com (Shamil D.) writes:
>
> > entry .e -validate key -vcmd {regexp {^[0-9]*\.?[0-9]{0,2}$} %P}
>
> Yes indeed.
>
> If you allow signage, beware that [+-] is illegal regexp (incomplete
> range) so you need [-+]:
>
> entry .e -validate key -vcmd {regexp {^[-+]?[0-9]*\.?[0-9]{0,2}$} %P}
>
>
> I usually specify an -invalidcommand, which can be as simple as bell:
>
> entry .e -validate key -vcmd {regexp {^[-+]?[0-9]*\.?[0-9]{0,2}$} %P}
\
> -invalidcommand bell
>
> but I like to do a little flash:
>
> entry .e -validate key -vcmd {regexp {^[-+]?[0-9]*\.?[0-9]{0,2}$} %P}
\
> -invalidcommand {invalid_entry_alert .e}
>
> # Alert the user of a bad entry by ringing the bell and flashing a
bright background
> # color. The optional "time" argument tells how many milliseconds
to flash.
>
> proc invalid_entry_alert { win {time 70}} {
> catch {
> set bg [$win cget -bg]
> if { ![string equal $bg $::PREF::brightcol] } {
> bell
> if { [string length $bg] } {
> $win configure -bg $::PREF::brightcol
> after $time [list $win configure -bg $bg]
> }
> }
> }
> }
>
> # Preferences; code them as you ummm prefer.
> namespace eval PREF {
> variable brightcol yellow
> }
>
> Donald Arseneau asnd@triumf.ca
- Next message: George Petasis: "Bug in Tk_HandleEvent stops tkdnd from working under unix..."
- Previous message: lvirden_at_gmail.com: "Re: is there a loadable Expect out there ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|