Ensuring numeric input

Cubist at aol.com Cubist at aol.com
Thu Oct 27 05:51:29 EDT 2005


sez michaell at unimelb.edu.au:
>How can I prevent users from being able to make non-number values in 
>a field? Simply preventing non-numeric keys is not enough because I 
>need to prevent things that use characters that are in valid numbers 
>to make non-numbers like 1.2.3 or -1.2-3.
   Something like this might work:

local OldValue

on keyDown
  put me into OldValue
  send "CheckMe" to me in 10 milliseconds
  -- adjust the "10" value as necessary to get good results
  pass keyDown
end keyDown

on CheckMe
  if (the value of me) is not a number then
    beep
    put OldValue into me
  end if
end CheckMe

   The CheckMe handler can include whatever procedure you like for handling 
non-numeric input; I just went with 'beep' for audio feedback that Something Is 
Wrong, plus restoring the former (known to be numeric) value. Hope this 
helps...



More information about the use-livecode mailing list