How to allow only numeric (0-9) in HTML inputbox using jQuery?
How to allow only numeric (0-9) in HTML inputbox using jQuery?
<input type="text" id="topperstest" name="topperstest" placeholder="Enter Your number here">
here is the code that help you and allow you to enter only numeric value to the textfield.
jQuery Allow Only Numbers
$(function () {
$('#topperstest').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
var key = e.keyCode;
if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
How to allow only numeric (0-9) in HTML inputbox using jQuery?
Reviewed by Dhaneshwar
on
10:21:00 PM
Rating:
No comments: