Page 1 of 1
Only allow numerics
Posted: Thu Oct 16, 2008 4:56 pm
by warrenk
Is there a way to only allow numerics to be entered in a field.
ie. if the user tries to enter a non numeric, the character is ignored.
Warren
Posted: Thu Oct 16, 2008 5:24 pm
by SparkOut
The (v. 3 at least) Resource Centre has some info about this.
Under "Sample Scripts" > "Text" there is a section "Accepting only digit characters during data entry" which suggests
Code: Select all
on keyDown theKey
if theKey is not a number then beep
else pass keyDown
end keyDown
is a good place from which to start.
You could leave out the beep obviously. In order to catch non-alphanumeric keystrokes, like backspace and delete you will need to use a variation, which handles the rawKeyDown message, and check for the character number relating to the keys you need to test, such as backspace.
Posted: Thu Oct 16, 2008 5:38 pm
by warrenk
Thanks SparkOut...this works!
Warren