Target all inputs
HTML
<label for="first">First</label><br>
<input type="number" min="0" />
<br><br>
<label for="Second">Second</label><br>
<input type="number" min="0" />
JavaScript
// Select your input element.
var numInput = document.querySelector('input');
// Listen for input event on numInput.
numInput.addEventListener('input', function(){
// Let's match only digits.
var num = this.value.match(/^\d+$/);
if (num === null) {
// If we have no match, value will be empty.
this.value = "";
}
}, false)