I’m trying to check for a valid time value it can be anything between 00 hours 00 Mins and 00 secs and 23 hours 59min and 59 secs.
I want it to check that it matches exactly HH:MM:SS with 0 being used if there no information for part not sure if I am explain this well so an example would be.
If the time was 23 mins and 5 secs it would be
00:23:05 and reject 23:05
The expression I think is right is
^(?:(?:([01]\d|2[0-3]):)([0-5]\d):)([0-5]\d)$
I am using jQuery but as far as I know there no easy way to validate time.
Am I correct?
That looks okay to me, but if you’re just validating, it would be easier not to use grouping constructs when you don’t need to, which would leave something like:
That only uses grouping for the alternation operator, which makes it much easier to read, IMO.