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]?
In your 2nd regex, you need to remove that ?
from the first part, and make it [1-5]
instead of [0-5]
:
[0-9]|[1-5][0-9]
And if you want to be flexible enough to allow both 7
and 07
, then use [0-5]
:
[0-9]|[0-5][0-9]
And then, simplifying the above regex, you can use:
[0-5]?[0-9] // ? makes [0-5] part optional