Only allow numerics

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Only allow numerics

Post by warrenk » Thu Oct 16, 2008 4:56 pm

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

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Oct 16, 2008 5:24 pm

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.

warrenk
Posts: 110
Joined: Sun Sep 21, 2008 5:39 am

Post by warrenk » Thu Oct 16, 2008 5:38 pm

Thanks SparkOut...this works!

Warren

Post Reply