I want a regex to test if the value entered in the input field matches using Javascript.
If user enters input say 20h or 20m the error message shouldn't be displayed. Also, when user inputs 20.0h or 20.0m, the error message shouldn't be displayed.
If user inputs only 20 with no units (h or m), then the error message should be displayed.
Basically, the input field should validate if the value has number followed by h or m.
I have tried the pattern like below,
const input = '20.0h';
const isValid = /^[0-9]+(h|m)$/.test(input);
This doesn't work for input with floating integers.
I am not knowing how to rewrite the regex to check for input like 20.0 or 30.0 or 4.0 .
Could someone help me with this? Thanks.