Skip to content

Instantly share code, notes, and snippets.

@tamboer
Last active December 14, 2015 21:48
Show Gist options
  • Save tamboer/5153350 to your computer and use it in GitHub Desktop.
Save tamboer/5153350 to your computer and use it in GitHub Desktop.
untested preg_match for valid time
<?php
public function isValidTime($time,$is24Hours=true,$seconds=false) {
$pattern = "/^".($is24Hours ? "([1-2][0-3]|[01]?[1-9])" : "(1[0-2]|0?[1-9])").":([0-5]?[0-9])".($seconds ? ":([0-5]?[0-9])" : "")."$/";
if (preg_match($pattern, $time)) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment