Date format validation in PHP


/ Published in: PHP
Save to your folder(s)

"YYYY-MM-DD" change pattern your fit code


Copy this code and paste it in your HTML
  1. function checkDateFormat($date)
  2. {
  3. //match the format of the date
  4. if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts))
  5. {
  6. //check weather the date is valid of not
  7. if(checkdate($parts[2],$parts[3],$parts[1]))
  8. return true;
  9. else
  10. return false;
  11. }
  12. else
  13. return false;
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.