Page 1 of 1

Formatting Numeric Field

Posted: Wed Dec 03, 2008 7:44 pm
by warrenk
I created a field where I am only allowing numbers and a decimal place. Is there anyway to prevent more then one decimal place? If I use the code below, I can only allow numerics and a decimal place. The problem is I can't prevent multiple decimal places.

on keyDown theKey
if theKey is a number or theKey = "." and the length of me <10 then
pass keyDown
else
end if
end keyDown

Thanks!
Warren

Posted: Wed Dec 03, 2008 8:34 pm
by Janschenkel
Almost there - just need to put in an extra check.

Code: Select all

on keyDown theKey 
  if theKey is a number or theKey = "." and the length of me <10 then
    if theKey is not "." or "." is not in the text of me then
      pass keyDown 
    end if
  end if 
end keyDown
Bear in mind that this doesn't help when the user pastes or drag-and-drops text into your field. So you'll also have to write handlers for the 'pasteKey' and 'dragDrop' messages.

HTH,

Jan Schenkel.

Posted: Wed Dec 03, 2008 8:41 pm
by warrenk
Awesome!!! Thanks for the help Jan!

Warren