Created
December 24, 2022 14:09
-
-
Save web-elite/468032d8c7bb912e25710f7b60ea4db8 to your computer and use it in GitHub Desktop.
filter inputs with numbers only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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