Last active
December 14, 2015 21:48
-
-
Save tamboer/5153350 to your computer and use it in GitHub Desktop.
untested preg_match for valid time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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