javascript regexp for numbers between 00-59 (seconds)

前端 未结 4 906
栀梦
栀梦 2021-01-19 15:03

I want to check if a field is a valid time value (just seconds). So I want to accept the numbers from 0 to 59. I came out with this:

[0-5][0-9]?
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 15:44

    If you want the 0 to be optional, move the ? to just after the [0-5] instead.

    [0-5]?[0-9] should do it.

提交回复
热议问题