My project uses a text field for a user to submit a math answer. (I tried input=“number” but this was not working for me). I want to limit the input to 0-9, delete, backspace, enter and the left and right arrow keys. It should also only allow a max of 2 digits.
The closest I’ve been was
<input type="text" id="answer" name="answer" onkeypress='return event.charCode >= 48 && event.charCode <= 57'> ```' But it's not a good solution. It only allows number input, but not the other buttons. Also I didn't like that it was inline, I thought maybe it should be with the rest of my JS. How could I make this validation?