Javascript - > Date validation not happening when Imask is used

Javascript - > Date validation not happening when Imask is used

Dear All

Pls visit following link


the top most field i.e.

Arrest Date formated  Pls enter dd-mm-yyyy format

when I enter date 50-55-2222  (dd-mm-yyyy) format

the Javascript function chkDate()  displayes the the day, month and year  correctly but not validated

i avail Year, Month and Day as follow (even tried  parseInt)

  1.  var yr=parseInt(idate.substring(6,10));
  2.    var mm=parseInt(idate.substring(3,5));
  3.    var dd=parseInt(idate.substring(0,2));

When I try

  1. if (dd > 31 ) 
  2.    {
  3.     alert ("Day cannot be Greater than 31  ");
  4.     inpdate.focus();
  5.     return false;
  6.    }
Validation doesnot takes place

However without mast the validation is working fine

please help

my javascript function to validate Date

function chkDate(inpdate)
{
idate=inpdate.value;
 
if ( empty(stripSpaces(idate))) 
  {
   return true;
  }
if (idate.length < 10  )
  {
    alert("date cannot be less  than 10 characters and should be in format dd-mm-yyyy") ;
inpdate.focus();
return false;
  }  
if (idate.length > 10  )
  {
    alert("date cannot exceed more than 10 characters and should be in format dd-mm-yyyy") ;
inpdate.focus();
return false;
  }
  
 
 var dsh1 = idate.substring(3,2);
 var dsh2 = idate.substring(6,5);
 if (dsh1 != "-" ) 
   {
     alert ("Enter date in dd-mm-yyyy format >>> there is no '-' after day ");
     inpdate.focus();
     return false;
   }
if (dsh2 != "-" ) 
   {
   alert ("Enter date in dd-mm-yyyy format >>> there is no '-' after month  ");
   inpdate.focus();
   return false;
   }
   var yr=parseInt(idate.substring(6,10));
   var mm=parseInt(idate.substring(3,5));
   var dd=parseInt(idate.substring(0,2));
 alert(' After parseInt \n Year of the input Date '+yr+'\n Month of the input Date '+mm+'\n Day of the input Date '+dd );
 if (isNaN(dd)) 
   {
     alert ("Day of month  should be numeric ");
     inpdate.focus();
     return false;
   }
if (isNaN(mm)) 
    {
     alert ("Month should be numeric ");
inpdate.focus();
     return false;
    }
if (isNaN(yr)) 
   {
    alert ("Year should be numeric ");
    inpdate.focus();
     return false;
   }
var tdate=new Date();
var cyr=tdate.getYear();
  


if (nyr <  yr ) 
      alert ("Year should  be less than or equal to year  "+cyr);
 inpdate.focus();
      return false;
     }
 
if (dd < 1) 
    { 
      alert ("Day of month cannot be less than 1 ");
 inpdate.focus();
      return false;
     }
if (dd > 31 ) 
   {
    alert ("Day cannot be Greater than 31  ");
    inpdate.focus();
    return false;
   }
 
if (mm > 12 || mm < 1 ) {
  alert ("Month should be between 1 and 12  ");
  inpdate.focus();
  return false;
  }
if (mm == 6 || mm == 9 || mm==11 ) {
   if (dd > 30 ) { 
   alert ("There are 30 days in June, September and November  !!  please correct day ");
    inpdate.focus();
   return false;     
   } 
 if (mm==2) 
     { 
  
       var b=parseInt(yr /4); 
       if (isNaN(b)) {
    alert( "Check no.of days in February NOT valid");
 inpdate.focus();
      return false ; 
   }
        if (dd>29)  {
    alert("Check no.of days in February NOT valid days in February cannot exceed 29");
    inpdate.focus();
return false ; 
   }    
        if (dd==29 && ((yr/4)!=parseInt(yr/4))) {
    alert( "Check no.of days !! This is NOt leap year  ");
    return false  ; 
        } 
}
return true ;
}