I have an input of type "text" where I want the user to be allowed to write inside just integers from -99 to 99.
The code so far is the following:
<input type="text" pattern="-?[0-9]{,2}" oninput="this.value=this.value.replace(/[^0-9\-]/g,'');">
The pattern returns valid=true even if the user just writes the minus sign (-) and this is not correct.
About the oninput, when the user writes a 3-digit number, the number remains in the field. The wanted behavior is to remove the third digit from the number.
Any ideas what to add to the pattern and the oninput in order to have correct results?
I have managed to do what I really wanted with a bit of JQuery.
Now the user can write ONLY numbers and the validity works as expected.
Here is the link: https://jsfiddle.net/panos78/2ctaonwL/
in case someone wants to see it how it works.