User Guide
TextField.restrict 745
Description
Method; replaces a range of characters, specified by the beginIndex and endIndex parameters, in
the specified text field with the contents of the
text parameter.
Example
The following example creates a text field called my_txt and assigns the text dog@house.net to
the field. The
indexOf() method is used to find the first occurrence of the specified symbol (@).
If the symbol is found, the specified text (between the index of 0 and the symbol) replaces with
the string
bird. If the symbol is not found, an error message writes to the log file.
this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 22);
my_txt.autoSize = true;
my_txt.text = "dog@house.net";
var symbol:String = "@";
var symbolPos:Number = my_txt.text.indexOf(symbol);
if (symbolPos>-1) {
my_txt.replaceText(0, symbolPos, "bird");
} else {
trace("symbol '"+symbol+"' not found.");
}
TextField.restrict
Availability
Flash Player 6.
Usage
my_txt.restrict:String
Description
Property; indicates the set of characters that a user may enter into the text field. If the value of the
restrict property is null, you can enter any character. If the value of the restrict property is
an empty string, you can’t enter any character. If the value of the
restrict property is a string of
characters, you can enter only characters in the string into the text field. The string is scanned
from left to right. A range may be specified using the dash (-). This only restricts user interaction;
a script may put any text into the text field. This property does not synchronize with the Embed
Font Outlines check boxes in the Property inspector.
If the string begins with ^, all characters are initially accepted and succeeding characters in the
string are excluded from the set of accepted characters. If the string does not begin with ^, no
characters are initially accepted and succeeding characters in the string are included in the set of
accepted characters.
Example
The following example allows only uppercase characters, spaces, and numbers to be entered into
a text field:
my_txt.restrict = "A-Z 0-9";