8.6. Setting Allowable Characters for Input
Problem
You want to restrict allowable characters for an input text field or text input component instance.
Solution
Use the Character Options to embed only those characters you want to allow the user to input.
Use the text field’s restrict property to assign a list or range of characters to include or not include.
Discussion
If you are using an input text field, there are two ways you can restrict the allowable characters. One way is to embed the font and to use the Character Options to specify which characters to embed. Because only that subset of characters gets embedded, the user can enter only those characters. For example, if you want to make sure that a user can only enter a number into an input field, you can embed only the number characters.
The downside of relying on embedding a font to restrict allowable characters is that embedded fonts increase the file size of the Flash movie. You can use ActionScript to restrict the allowable characters even with device fonts. The restrict property for a text field determines what characters can be entered by the user. You can assign a string value to the restrict property that contains all the characters you want to allow. The following example restricts the allowable characters for tInputField to the lowercase letters from a to g and the uppercase letters X, Y, and Z:
tInputField.restrict = "abcdefgXYZ";
The restrict property affects what characters an input text field can display. If the user ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access