Skip to content

Instantly share code, notes, and snippets.

@svecon
Last active December 21, 2015 06:49
Show Gist options
  • Select an option

  • Save svecon/6267280 to your computer and use it in GitHub Desktop.

Select an option

Save svecon/6267280 to your computer and use it in GitHub Desktop.
Validates user's input date.
protected function checkInputDate($string)
{
$try = date_parse($string);
if ($try['error_count'] > 0)
return false;
try { $try = new DateTime($string); }
catch (Exception $e) { return false; }
$sep = '-.\/';
if(preg_match("/[^0-9$sep]+/", $string) == 1)
return false;
if(preg_match("/[$sep]/", $string) == 0)
return false;
if (count(preg_split("/[$sep]/", $string)) != 3)
return false;
if (strtotime($string) === false)
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment