Manipulating Text-Field Contents

When you define a text field as input text, you give your viewers the freedom to enter and edit information. You’ve seen how this information can be used in expressions with other actions or concatenated and displayed in dynamic text fields. Often, however, you need to analyze the text entered by the viewer before using it. You may want to tease out certain words or identify the location of a particular character or sequence of characters. If you require viewers to enter an email address in an input field, for example, you can check to see whether that address is in the correct format by looking for the @ symbol. Or you could check a customer’s telephone number, find out the area code based on the first three digits, and personalize a directory or news listing with local interests.

This kind of parsing, manipulation, and control of the information within text fields is done with a combination of the Selection object and the String object. The Selection object lets you control the focus of multiple text fields and the position of the insertion point within a focused text field. The String object lets you retrieve and change the characters inside a text field.