设为首页 - 加入收藏 大连站长网 (https://www.0411zz.cn)- 大型站长资讯类网站,站长百科,建站经验,电子商务,云计算!
热搜: 公开 隔空手势
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

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

发布时间:2021-05-26 05:06 所属栏目:[Unix] 来源:站长网
导读:?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="initHandle


<?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
source="{username}"
property="text"
minLength="6" maxLength="16"
tooLongError="不能多于16个字符" tooShortError="不能低于六位"
required="true"
invalid="NAMEValidator_invalidHandler(event)"
/>
<mx:NumberValidator source="{age}"
domain="int" allowNegative="false" maxValue="60" minValue="18"
required="true" property="text"
exceedsMaxError="不能大于60" lowerThanMinError="不能低于十八"
invalid="AGEValidator_invalidHandler(event)"
/>
<mx:PhoneNumberValidator
minDigits="11" property="text"
source="{phone}"
required="true"
invalid="PHONEValidator_invalidHandler(event)"/>
</fx:Declarations>
<mx:Panel>
<mx:Form>
<mx:FormItem label="name">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem label="age">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem label="phone">
<mx:TextInput/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="验证"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</s:Application>

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

推荐文章