Use Validator to validate data from a form
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
import mx.events.ValidationResultEvent;
private function invalidHandler(event:ValidationResultEvent):void {
usernameItem.setStyle("color", 0xFF0000);
}
private function validHandler(event:ValidationResultEvent):void {
usernameItem.setStyle("color", 0x000000);
}
</mx:Script>
<mx:Form>
<mx:FormItem id="usernameItem" label="Name">
<mx:TextInput id="username"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button id="button" label="Submit" />
</mx:FormItem>
</mx:Form>
<mx:Validator id="validator" source="{username}" property="text" invalid="invalidHandler(event)" valid="validHandler(event)" listener="{null}" />
</mx:Application>
Related examples in the same category