Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"
Xmlns:s= "Library://ns.adobe.com/flex/spark"
xmlns:mx= "Library://ns.adobe.com/flex/mx" minwidth= "955" minheight= "600"
Creationcomplete= "Inithandler (event)" >
<fx:Script>
<! [cdata[
Import Mx.controls.Alert;
Import mx.events.FlexEvent;
Import mx.events.ValidationResultEvent;
Import Mx.validators.Validator;
private Var error1:string;
private Var error2:string;
private Var error3:string;
protected function Inithandler (event:flexevent): void
{
}
protected function Btn_clickhandler (event:mouseevent): void
{
TODO auto-generated Method Stub
var Validatearray:array=validator.validateall (
[Namevalidator,agevalidator,phonevalidator]);
if (validatearray.length==0)
{
Alert.show ("Success!") ");
}else
{
Alert.show (error1+ "\ n" +error2+ "\ n" +error3);
}
}
protected function Namevalidator_invalidhandler (event:validationresultevent): void
{
Error1 =event.message;
}
protected function Agevalidator_invalidhandler (event:validationresultevent): void
{
Error2 =event.message;
}
protected function Phonevalidator_invalidhandler (event:validationresultevent): void
{
Error3 =event.message;
}
]]>
</fx:Script>
<fx:Declarations>
<mx:stringvalidator id= "Namevalidator"
Source= "{username}"
property= "Text"
Minlength= "6" maxlength= "16"
Toolongerror= "cannot be more than 16 characters" tooshorterror= "cannot be less than six bits"
Required= "true"
Invalid= "Namevalidator_invalidhandler (event)"
/>
<mx:numbervalidator id= "Agevalidator" source= "{Age}"
domain= "int" allownegative= "false" maxvalue= "a" minvalue= "18"
Required= "true" property= "text"
Exceedsmaxerror= "can not be greater than" lowerthanminerror= "can not be less than 18"
Invalid= "Agevalidator_invalidhandler (event)"
/>
<mx:phonenumbervalidator id= "Phonevalidator"
mindigits= "One" property= "text"
Source= "{Phone}"
Required= "true"
Invalid= "Phonevalidator_invalidhandler (event)"/>
</fx:Declarations>
<mx:Panel>
<mx:Form>
<mx:formitem label= "Name" >
<mx:textinput id= "username"/>
</mx:FormItem>
<mx:formitem label= "Age" >
<mx:textinput id= "Age"/>
</mx:FormItem>
<mx:formitem label= "Phone" >
<mx:textinput id= "Phone"/>
</mx:FormItem>
<mx:FormItem>
<mx:button label= "Verify" id= "BTN" click= "Btn_clickhandler" (event)/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</s:Application>