Skip to content

Instantly share code, notes, and snippets.

@adamjforster
Created August 1, 2011 11:06
Show Gist options
  • Save adamjforster/1117940 to your computer and use it in GitHub Desktop.
Save adamjforster/1117940 to your computer and use it in GitHub Desktop.
Tests if a string is a valid time for a 24hr clock.
function is_valid_time(value) {
/* Validates that a string is a valid time in either of the following
* formats:
*
* HH:MM
* HH:MM:SS
*/
regex = /^([01]\d|2[0-3])(:[0-5]\d){1,2}$/;
return regex.test(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment