Recipe 9.6. Setting a Field s Maximum Length


Recipe 9.6. Setting a Field's Maximum Length

Problem

You want to limit the length of the string input into 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 he desires. However, you may have good reason to want to set a maximum. For example, if an input field prompts a user for his 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:

field.maxChars = 6;  // maximum of 6 characters can be input

Set maxChars to null to allow an entry of unlimited length, if you've previously assigned a non-null value to maxChars.

See Also

Recipe 9.5




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net