flex中validateall()方法, 多Item驗證 ,結果統一提示

來源:互聯網
上載者:User

<?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 stubvar 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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.