Regular expression for matching HH:MM time format

前端 未结 19 2686
甜味超标
甜味超标 2020-11-22 17:25

I want a regexp for matching time in HH:MM format. Here\'s what I have, and it works:

^[0-2][0-3]:[0-5][0-9]$

This matches everything from

19条回答
  •  暖寄归人
    2020-11-22 18:11

    Amazingly I found actually all of these don't quite cover it, as they don't work for shorter format midnight of 0:0 and a few don't work for 00:00 either, I used and tested the following:

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

提交回复
热议问题