myValidators.as

package myCompenent
{
 import mx.validators.ValidationResult;
 import mx.validators.Validator;
 public class myValidators extends Validator
 {
  public function myValidators()
  {
   super();
  }
  
  private var results:Array;
  //重写验证函数
  override protected function doValidation(value:Object):Array
  {
   var s:String= value as String;
   results=[];
   results=super.doValidation(value);
   if(results.length>0)
    return results;
   if(s.length>6)
   {
    results.push(new ValidationResult(true,"text","StringTooLong","字符长度超过6了"));
   }
   return results;
  }
 }
}

main.mxml

<?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/halo" 
 minWidth="1024" minHeight="768" xmlns:myCompenent="myCompenent.*">
 
 <fx:Declarations>
  <myCompenent:myValidators />  
 </fx:Declarations>
 <s:Panel x="131" y="54" width="405" height="200" title="自定义验证组件">
  <s:TextInput x="133" y="25" />
  <s:Label x="133" y="55"  width="128" height="29" text="{textinput.errorString}" />
  <s:Button x="133" y="92" label="验证" />  
 </s:Panel>
</s:Application>



 

 

相关文章:

  • 2021-11-20
  • 2022-01-13
  • 2021-12-17
  • 2021-11-06
  • 2022-12-23
  • 2021-07-01
  • 2022-01-17
猜你喜欢
  • 2021-12-23
  • 2022-01-09
  • 2021-12-17
  • 2022-12-23
  • 2022-02-19
  • 2021-12-03
  • 2021-08-21
相关资源
相似解决方案