Good morning everyone, I have the following function that validates that only numerical characters can be entered in a text input. The problem is that if I press the Dead key twice, 'ยด is entered in the text input.
input_numeric.onkeydown = numericKeyboard;
function numericKeyboard(e) {
if (e.key != 0 && e.key != 1 && e.key != 2 && e.key != 3 && e.key != 4 && e.key != 5 && e.key != 6 && e.key != 7 && e.key != 8 && e.key != 9) {
e.preventDefault();
}
}
Please someone can help me solve my problem.
Instead of preventing default, just don't allow any of the not allowed input
Using the input event will handle typing and pasting
If you insist on preventDefault, we can try this. Note that the input event cannot use preventDefault since it triggers after input