Book Image

LiveCode Mobile Development Cookbook

By : Dr. Edward Lavieri
Book Image

LiveCode Mobile Development Cookbook

By: Dr. Edward Lavieri

Overview of this book

Table of Contents (17 chapters)
LiveCode Mobile Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Restricting the user input


There is an old saying: garbage in and garbage out. This refers to users entering invalid data into a computerized system. Fortunately, we have some control over what users can input. This recipe shows you how this is done.

How to do it...

To restrict user input, perform the following steps:

  1. Create a new main stack.

  2. Drag a text input box to the stack's card.

  3. Add the following code to the text input box:

    on keyDown theKey
      if theKey is in "abcdefghijklmnopqrstuvwxyz" then
        pass keyDown
      else
         beep
        end if
      end keyDown

How it works...

By evaluating the user's input prior to allowing it to pass to the next level in the message chain, we can selectively accept or reject it.

There's more...

In this recipe, we intercepted messages from the keyboard using our on keyDown handler. In LiveCode, messages are triggered by events such as the mouseDown message being sent when the user selects/clicks on an object. In this example, the event was the clicking of the object and...