enter only digits in textbox using javascript jsfiddle

Solutions on MaxInterview for enter only digits in textbox using javascript jsfiddle by the best coders in the world

showing results for - "enter only digits in textbox using javascript jsfiddle"
Greta
07 Sep 2018
1Number : <input type="text" name="quantity" id="quantity" />&nbsp;<span id="errmsg"></span>
2
3
4<script>
5  
6 $(document).ready(function () {
7  //called when key is pressed in textbox
8  $("#quantity").keypress(function (e) {
9     //if the letter is not digit then display error and don't type anything
10     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
11        //display error message
12        $("#errmsg").html("Digits Only").show().fadeOut("slow");
13               return false;
14    }
15   });
16});
17 </script>