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
Formatting Numeric Field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Almost there - just need to put in an extra check.
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.
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
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com