const onlyNum = document.querySelector('.only-num'); onlyNum.oninput = () => onlyNum.value = onlyNum.value.replace(/\D/g, '');
<input type="text" class="only-num" />