I need a regex in a form in order to make sure the input either:
- starts with + or - and then has numbers (for instance: +120 or -15)
- or is an exact hour, for instance: 17:20 or 15:23
The regex I came up with is:
^[+-][\d]*|[\d]{2}:[\d]{2}$
But it doesn't seem to work properly: each expression works separately (^[+-][\d]*$
or ^[\d]{2}:[\d]{2}$)
but together with the | operator, it allows the input +120sds
where it didn't when the expression was tested separately.