Reputation:
I'm not an expert to regular expressions, but I tried to validate the user input for a time field with it.
My current regex: /^([0-9]|0[0-9]):[0-5][0-9]$/
It should validate anything positive between 0:01 and 9:59, but it also give positive return to 0:00.
Can you please help me to modify my regular expression to exclude 0:00?
Thanks a lot!
Upvotes: 0
Views: 248
Reputation: 2139
Here is the regex you are looking for.
^((?!(0:00)|(00:00)$)0?[0-9]:[0-5][0-9])$
Uses the concept of negative look ahead. Using negative lookahead, you can say match everything except 0:00
and 00:00
.
Hope this helps!
Upvotes: 2