• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    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渐变色制作圆角橙色按钮示例代码
    下一篇:flex中如何用图像给按钮做皮肤
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

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