php验证是否日期格式代码 验证日期格式函数分享

 验证日期格式:YYYY-MM-DD

 函数如下需要的拿去哦:
 

  1. function checkDateFormat($date) { 
  2.  
  3.  // match the format of the date 
  4.  
  5.  if (preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/"$date$parts)) { 
  6.  
  7.  // check whether the date is valid of not 
  8.  
  9.  if (checkdate($parts[2], $parts[3], $parts[1])) { 
  10.  
  11.  return true; 
  12.  
  13.  } else { 
  14.  
  15.  return false; 
  16.  
  17.  } 
  18.  
  19.  } else { 
  20.  
  21.  return false; 
  22.  
  23.  } 
  24.  
  25.  }