1document.querySelector(".your_class").addEventListener("keypress", function (evt) {
2 if (evt.which != 8 && evt.which != 0 && evt.which < 48 || evt.which > 57)
3 {
4 evt.preventDefault();
5 }
6});
7
8// 0 for null values
9// 8 for backspace
10// 48-57 for 0-9 numbers