Facebook

Thursday, September 1, 2011

Codeigniter Callback Function to validate date.


function validdate($str){
    if ( ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $str) ) {
       $arr = split("-",$str);// splitting the array
       $yy = $arr[0];         //first element of the array is year
       $mm = $arr[1];         //second element is month
       $dd = $arr[2];         //third element is days
       if( checkdate($mm, $dd, $yy) ); {
          return true;
       }
   }
   else {
       $this->form_validation->set_message('validdate', 'Check format of %s field.');
       return FALSE;
   }