c# - regex checking time -
i've got following regex:
^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$
this accept 00:00:00
or 00:00
or 00
don't want this. can accept 00:01
or 00:00:01
not zeros.
what have missed in regex?
you can use negative lookaheads solve this:
^(?!^(\d|0)*$)(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$
the negative lookahead matches nondigits , zeroes. if have zeroes in time, fail match.
you can see in more detail on www.debuggex.com.
Comments
Post a Comment