packages to import:
import mx.events.ValidationResultEvent;
import mx.validators.Validator;
import mx.validators.StringValidator;
mxml Tag to use:
<mx:StringValidator id=”strVal” property=”text” />
on what control:
<mx:TextInput x=”256″ y=”10″ id=”txtuname” width=”206″ tabIndex=”1″/>
ActionScript code to use:
strVal.source=txtuname;
strVal.required=true;
strVal.requiredFieldError=”Enter Your User Name”;
var bill_result1:ValidationResultEvent=strVal.validate();
if(bill_result1.type==ValidationResultEvent.INVALID)
{
txtuname.setFocus();
Alert.show(bill_result1.message,this.title);
}
Hope you understand the code.Enjoy the code.
Posted by kumargandhi 
