var oInput = document.querySelector("input");oInput.onkeyup = function () { var value = this.value; if(value.search(/^\d+$/) != 0){ this.value = value.replace(/[^0-9]/g,''); } }