Regular expression for matching time in military (24 hour) format

后端 未结 11 760
庸人自扰
庸人自扰 2020-12-23 13:44

I would like a JavaScript regular expression that will match time using the 24 hour clock, where the time is given with or without the colon.

For example, I would li

11条回答
  •  遥遥无期
    2020-12-23 14:32

    I don't think regex is the right solution for this problem. Sure, it COULD be done, but it just seems wrong.

    Make sure your string is four characters long, or 5 characters with a colon in the middle. Then, parse each side and make sure that the left side is less than 24 and the right hand is less than 60.

    The regex solution is just so much more complicated.

提交回复
热议问题