How would i make a regex for HH-MM

Viewed 14

So the user has to type how many hours like show in the title but i want to have it where if they only needed 1 hour they wouldn't have to do for example 01-00 i want it to be possible for them to just do 1-0 as well or like 1-10 which would be 1 hour 10 minutes

1 Answers

You can add a quantifier to a regex using {x,y}.
Therefore \d{1,2}-\d{1,2} would take either 1 or 2 numbers for hours and minutes. Try it here https://regex101.com/r/k4RMho/1

Related