flex中validateall()方法实现多Item验证且结果统一提示

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了flex中validateall()方法实现多Item验证且结果统一提示脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
复制代码 代码如下:

<?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("成功啦!");
}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="不能多于16个字符" tooShortError="不能低于六位"
required="true"
invalid="NAMEValidator_invalidHandler(event)"
/>
<mx:NumberValidator id="AGEValidator" source="{age}"
domain="int" allowNegative="false" maxValue="60" minValue="18"
required="true" property="text"
exceedsMaxError="不能大于60" lowerThanMinError="不能低于十八"
invalid="AGEValidator_invalidHandler(event)"
/>
<mx:PhoneNumberValidator id="PHONEValidator"
minDigits="11" 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="验证" id="btn" click="btn_clickHandler(event)"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</s:Application>

脚本宝典总结

以上是脚本宝典为你收集整理的flex中validateall()方法实现多Item验证且结果统一提示全部内容,希望文章能够帮你解决flex中validateall()方法实现多Item验证且结果统一提示所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: