Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
79
rated 0 times [  81] [ 2]  / answers: 1 / hits: 119926  / 8 Years ago, fri, september 2, 2016, 12:00:00

When I'm giving input type number the letter e and special charecters are also displaying in input field. I want to display only digits. How to block them?





<input type=number>




More From » html

 Answers
2

Try preventing the default behaviour if you don't like the incoming key value:





document.querySelector(.your_class).addEventListener(keypress, function (evt) {
if (evt.which != 8 && evt.which != 0 && evt.which < 48 || evt.which > 57)
{
evt.preventDefault();
}
});

// 0 for null values
// 8 for backspace
// 48-57 for 0-9 numbers

<input type=number class=your_class>




[#60835] Wednesday, August 31, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anabellejaynav

Total Points: 176
Total Questions: 105
Total Answers: 105

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;