O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.8. Restricting the Maximum Field Length

Problem

You want to limit the length of the string input in a text field.

Solution

Set the text field’s maxChars property.

Discussion

By default, an input text field allows a user to type in as many characters as she desires. However, you may have good reason to want to set a maximum. For example, if an input field prompts a user for her two-character country code, you might want to prevent the user from entering more than two characters. Setting the maxChars property to a number limits the user input to that many characters.

myTextField.maxChars = 6;  // Maximum of six characters can be input

Set maxChars to null to allow an entry of unlimited length.

See Also

Recipe 8.7

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required