3 Replies Latest reply on Apr 27, 2010 12:23 PM by 55t56yh

    validating date and the slash caracter (/)

    55t56yh

      greets

      i have been locking for a script code to allow me put in a text box a valid date, but the code have to insert automatically de slash bar how it looks in this example  http://www.tunait.com/javascript/?s=mascara#codigo

      in the format dd/mm/yyyy

      how i can do that??


      thenks for any kind of help

       

      pd: and no, its not using the dataformater propertie

       

       

      **** Ive been working on it and i have this

       

      <?xml version="1.0" encoding="utf-8"?>
      <!-- http://blog.flexexamples.com/2007/08/13/validating-flex-forms-using-the-validator-classes/ -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle"  backgroundColor="gray" creationComplete="init();">
       
       
      <mx:Script>
           <![CDATA[
                import mx.controls.TextArea;
                
                var patron = new Array(2,2,4);
                
                public function mascara(txt:String){
                     
                     var aux:String=txt.replace("/","");     
                     aux=aux.replace("/","");               
                     var aux3:Array=new Array();
                     var l:Number=aux.length;
                     var cont:Number=0;
                     
                     if(l>1)
                     {aux3.push(aux.substring(0,2));cont=1;}
                     
                     if(l>3)
                     {aux3.push(aux.substring(2,4));cont=3;}
                     
                     if(l>=5)
                     {aux3.push(aux.substring(4,7));cont=l-1;}
                     
                          
                               
                     var salida:String="";
                     
                     if(l>1)
                     salida=aux3[0]+"/";
                     
                     if(l>3)
                     salida=aux3[0]+"/"+aux3[1]+"/";
                     
                     if(l>=5)
                     salida=aux3[0]+"/"+aux3[1]+"/"+aux3[2];
                     
                     if(cont!=0){
                          if(cont!=7)
                               salida=salida+aux.substring(cont+1,l);
                          else if(cont==7)
                               salida=salida+aux.substring(cont,l);     
                     }     
                     
                     if(salida!=""){                                 
                          txtfecha.text=salida;                    
                     }
                }
      
           ]]>
      </mx:Script>
      
           <mx:TextInput  keyUp="mascara(txtfecha.text)" id="txtfecha" maxChars="10" restrict="0-9,/" />
      </mx:Application>
      

       

       

      but when i launch the program, de textbox show me the numbers in wrong position, and i dont know where are the error