Form Validation
When allowing users (damn humans) to input data it is often desired (or necessary) to validate the entered data for correctness.
Flex provides several Validators that can be used with Forms to ensure entered user-entered data is correctly formatted.
Triggering Validation
Common triggers and events:
- TextInput / focusOut - triggers when the field loses focus
- TextInput / change - triggers when the value of the field changes
- Button / click - triggers when a button is clicked
Form Validation Example
<!-- Validators --> <mx:StringValidator source="{txtFirstName} property="text" maxLength="100" trigger="{btnOK}" triggerEvent="click" /> <mx:StringValidator source="{txtLastName} property="text" maxLength="100" trigger="{btnOK}" triggerEvent="click" /> <mx:EmailValidator source="{txtEmailAddress}" property="text" required="false" trigger="{txtEmailAddress}" triggerEvent="focusOut" /> <!-- Form --> <mx:Form id="frmContact"> <mx:FormHeading label="Contact Information"/> <mx:FormItem label="First Name:" required="true"> <mx:TextInput id="txtFirstName"/> </mx:FormItem> <mx:FormItem label="Last Name:" required="true"> <mx:TextInput id="txtLastName"/> </mx:FormItem> <mx:FormItem label="Email Address:" required="false"> <mx:TextInput id="txtEmailAddress"/> </mx:FormItem> <mx:FormItem label="Phone Number:" required="false"> <mx:TextInput id="txtEmailAddress"/> </mx:FormItem> <mx:FormItem> <mx:Button id="btnOK" label="OK"/> </mx:FormItem> </mx:Form>
More information on Validators...

