I’m new to react and as practise, I’m building a react app. The form has a duration input which expects the data either in minutes or hours eg. 132m or 2.5h. The function should return the number of hours based on the input or show error in alert that “Duration is in invalid format”.
How can I go about this? The value is string and so I was thinking of using duration.includes('m')
or duration.includes('h')
but the problem is it will accept “1h32” for example. I also want to know how float can be extracted from the string?