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

后端 未结 11 756
庸人自扰
庸人自扰 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:22

    I know this is an old question but here's a regex I came up with which seems to work.

    ^(([[0|1]\d)|(2[0-3]))[:]?([0-5]\d)$
    

    You can edit it on this regex site

    Edit I just realised that this answer ended up exactly the same as the accepted answer but I will leave it here at least for the value of the 'do it yourself' link

提交回复
热议问题