posts - 325,  comments - 25,  trackbacks - 0

          數(shù)據(jù)驗證
          內(nèi)置Validator類
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
             backgroundColor="#FFFFFF" width="550" height="300">
            
            <mx:Validator required="true" source="{fnametxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{fnametxt}"/>
            <mx:Validator required="true" source="{lnametxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{lnametxt}"/>
            <mx:Validator required="true" source="{addresstxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{addresstxt}"/>
            <mx:Validator required="true" source="{citytxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{citytxt}"/>
            <mx:Validator required="true" source="{statetxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{statetxt}"/> 
            <mx:ZipCodeValidator required="true" source="{ziptxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{ziptxt}"/>
            <mx:EmailValidator source="{emailtxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{emailtxt}"/>
            <mx:PhoneNumberValidator source="{phonetxt}" property="text"
              trigger="{validatebtn}" triggerEvent="click" listener="{phonetxt}"/>
             
            <mx:Panel title="Contact Info" width="500" height="250">
            <mx:Form>
              <mx:FormItem label="Name" direction="horizontal">
                <mx:TextInput id="fnametxt" />
                <mx:TextInput id="lnametxt" />
              </mx:FormItem>
              <mx:FormItem label="Address">
                <mx:TextInput id="addresstxt"/>
              </mx:FormItem>
              <mx:FormItem label="City State, Zip" direction="horizontal">
                <mx:TextInput id="citytxt"/>
                <mx:TextInput id="statetxt" width="20"/>
                <mx:TextInput id="ziptxt" width="50"/>
              </mx:FormItem>
              <mx:FormItem label="Phone">
                <mx:TextInput id="phonetxt"/>
              </mx:FormItem>
              <mx:FormItem label="Email">
                <mx:TextInput id="emailtxt"/>
              </mx:FormItem>
              <mx:Button id="validatebtn" label="Validate"/>
            </mx:Form>
            </mx:Panel>
          </mx:Application>

          使用errorString進行數(shù)據(jù)驗證
          如果Flex自帶的驗證組件無法滿足要求,可用ActionScript自定義,errorString屬性將以默認的紅色邊框和包括錯誤信息顯示
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
             backgroundColor="#FFFFFF" width="300" height="150">
             <mx:Script>
              <![CDATA[
               private function validate():void{
                 // check for length of 10
                 if(myText.text.length < 10){
                   // assign errorString to TextInput
                   myText.errorString = "This field requires at least 100 characters";
                 } else {
                   // remove errorString
                   myText.errorString = null;
                 }
               }
               ]]>
             </mx:Script>
             <mx:Panel title="Simple AS Validate" width="210" height="75">
               <mx:HBox width="100%" height="100%" paddingLeft="3" paddingTop="3">
                 <mx:TextInput id="myText" width="100"/>
                 <mx:Button label="Validate" click="validate()" />
               </mx:HBox>
             </mx:Panel>
          </mx:Application>

          posted on 2011-03-17 09:22 長春語林科技 閱讀(253) 評論(0)  編輯  收藏 所屬分類: flex
          <2011年3月>
          272812345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南皮县| 孝义市| 基隆市| 寻甸| 常熟市| 镇江市| 永仁县| 天峻县| 金阳县| 灌阳县| 青海省| 永靖县| 泰安市| 澄城县| 无棣县| 玉环县| 仁怀市| 丰原市| 清苑县| 阿拉善右旗| 喀什市| 裕民县| 随州市| 桃江县| 麻城市| 东至县| 甘南县| 军事| 个旧市| 茂名市| 疏勒县| 青冈县| 彩票| 连州市| 连南| 定兴县| 大城县| 兴化市| 瑞安市| 连城县| 马山县|