I have a stopwatch variable that can get value in the following format: I'm not that good with this regex thingy, but something that is for the most part Well was able to write but failed to validate if the hour is a single digit. Pass the regex near What should I change in regex to say that it should check any number, but should the fraction of the hour be 2 digits or more? Allow it to contain {2,} two or more characters If you want to see things that match And if you can not match, you can play with it Edit: Also, if you want to match up to only 59 in the hour / minute portion then HH: MM: SS Most of the time.
'HH' can go up to the last 24 hours - basically a valid number
1:10:09 , although it is invalid it should be part of the valid hour
01 .
// var stopWatchTime = '02: 10: 09 '; // valid // var stopwatchtime = '00: 10: 09 '; // valid // var stopwatchtime = '1234: 10: 9'; // valid // var stopWatchTime = ': 10: 09'; // invalid // var stopWatchTime = 'ax: 10: 09'; // invalid var stopWatchTime = '1:10:09'; // invalid, should be 01:10:09. If (! Stopwatchtime match (/ ^ \ d +: \ d {2}: \ d {2} $ /)) {Warning ('Invalid Time -' + Stopwatchtime); } And {alert ('valid time -' + stopwatchtime); }
/ ^ \ d {2,}: \ d {2}: \ d { 2} $ /
< Code> ^ \ d {2,}: (?: [0-5] \ D): (?: [0-5] \ d) $
Comments
Post a Comment