Regular expression for matching HH:MM time format

前端 未结 19 2464
甜味超标
甜味超标 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 17:49

    Matches:

    2:9
    2:09
    2:59
    02:9
    02:09
    02:59
    23:59
    

    Use it:

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

提交回复
热议问题