2 Replies Latest reply on Jan 3, 2011 10:22 AM by miguel8312

    datevalidation via actionscript suggestions

    miguel8312 Level 3

      hey guys a few months back i need a function to validate the string being read from a csv file on a flex web app to make sure the string was formatted as

      dd-mmm-yy in other words 01-mar-10 however i couldnt figuered it out using any native AS3 classes or any flex datevalidators. So i put this simple function together. I would love to know if there is another way to do this.  A MORE ELEGANT  way to do this i just havent figuered it out so please if you have one please post it up here.


      here is my function

       public function DateValidation(DateValue:String):Boolean
                   var index:int;
                   var MonthLowerNumber:Number = 1;
                   var MonthHighestNumberRange:Number = 31;
                   var YearLowerNumberRange:Number = 1;
                   var YearHighestNumberRange:Number = 99;
                   /*variable used to split the month day and year*/
                   var Month:String;
                   var Day:Number;
                   var Year:Number;
                   var DateValidator:Boolean = true;
                   /*variables used to decide if in total the date will make it pass*/
                   var GoodMonth:String;
                   var GoodDay:String;
                   var GoodYear:String;
                   var GoodDash1:String;
                   var GoodDash2:String;
                   var Dash1:String;
                   var Dash2:String;
                   var monthLabels:Array = new Array("JAN",
                   /*check the lenght of the string being sent in*/     
                   if (DateValue.length == 9)
                   Day   = parseFloat(DateValue.substr(0,2)); 
                   Month = DateValue.substr(3,3).toUpperCase();
                   Year  = parseFloat(DateValue.substr(7,2));
                    Dash1 = DateValue.substr(2,1);
                   Dash2 = DateValue.substr(6,1);
                   else if (DateValue.length == 8)
                       Day   = parseFloat(DateValue.substr(0,1)); 
                       Month = DateValue.substr(2,3).toUpperCase();
                       Year  = parseFloat(DateValue.substr(6,2));
                       Dash1 = DateValue.substr(1,1);
                       Dash2 = DateValue.substr(5,1);
                  /*check the day*/
                   if ( Day >= MonthLowerNumber && Day <= MonthHighestNumberRange) { GoodDay='Y' }
                   /*check the year*/
                       if ( Year >= YearLowerNumberRange && Year <= YearHighestNumberRange) { GoodYear ='Y'}
                               else(GoodYear ='N' );
                           if (Dash1 == '-'){GoodDash1 ='Y'}
                                  else {GoodDash1 = 'N'};
                          if(Dash2 == '-'){GoodDash2 ='Y'}
                                      else {GoodDash2 = 'N'};
                   /******search array for the value being sent in from the main app.*/
                   /*check the month*/
                    index =monthLabels.indexOf(Month);
                       if (index > 0) { GoodMonth='Y'}
                                   else { GoodMonth='N'};
                       if(GoodDay =='Y' && GoodYear=='Y' && GoodMonth=='Y'&& GoodDash1=='Y' && GoodDash2 =='Y' ){DateValidator =true}
                                       else {DateValidator = false};
                   return DateValidator;