Skip to content

Instantly share code, notes, and snippets.

@voku
Created June 5, 2014 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voku/dd277e9c660f38b8c3a3 to your computer and use it in GitHub Desktop.
Save voku/dd277e9c660f38b8c3a3 to your computer and use it in GitHub Desktop.
date format validation: Validate a date in "YYYY-MM-DD" format. - From http://snippetlib.com/php/date_format_validation
<?php
/**
* check for date-format
*
* @param string $date valid is only "YYYY-MM-DD"
*
* @return bool
*/
function checkDateFormat($date)
{
// match the format of the date
if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts))
{
// check whether the date is valid or not
if (checkdate($parts[2],$parts[3],$parts[1])) {
return true;
} else {
return false;
}
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment