I have a form and I need to fill it with numbers only and I want to not allow typing other characters in the input field using JavaScript.
I need a solution in JavaScript.
I have a form and I need to fill it with numbers only and I want to not allow typing other characters in the input field using JavaScript.
I need a solution in JavaScript.
You can replace all non-digit characters on the "input" event.
For example:
document.querySelector('input').addEventListener('input', function(e) {
this.value = this.value.replace(/[^\d]/g, '');
});
<input>