Skip to content

Instantly share code, notes, and snippets.

@web-elite
Created December 24, 2022 14:09
Show Gist options
  • Save web-elite/468032d8c7bb912e25710f7b60ea4db8 to your computer and use it in GitHub Desktop.
Save web-elite/468032d8c7bb912e25710f7b60ea4db8 to your computer and use it in GitHub Desktop.
filter inputs with numbers only
<script>
var inputNumberElite = document.querySelectorAll('input[type="number"]');
for (var i = 0, len = inputNumberElite.length; i < len; i++) {
inputNumberElite[i].addEventListener("keypress", function(evt) {
if (evt.which != 8 && evt.which != 0 && evt.which < 48 || evt.which > 57) {
evt.preventDefault();
}
})
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment