REGEX of HH: MM: SS may be negative

4

I'm working with HH: MM: SS and I have this% REGEX ^([0-1]?\d{0,4})(?::([0-5]?\d))?(?::([0-5]?\d))?$ I'm using the library InputMask but I'd like to work with negative hours example:

Effort: -200: 00: 00

Can I continue to use this regex or do I have to use another one?

    
asked by anonymous 05.01.2018 / 13:14

1 answer

4

Use -? at the beginning of REGEX so that the negative sign is optional:

 ^-?(?:[0-9]{0,4}):(?:[0-5][0-9]):(?:[0-5][0-9])$
    
08.01.2018 / 19:19