Created
June 8, 2020 14:00
-
-
Save gagimilicevic/de6e19869370aeb68092fe41c458a5cc to your computer and use it in GitHub Desktop.
Textbox accept only numbers (digits) using jquery
This file contains hidden or 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
Number : <input type="text" name="quantity" id="quantity" /> <span id="errmsg"></span> | |
$(document).ready(function () { | |
//called when key is pressed in textbox | |
$("#quantity").keypress(function (e) { | |
//if the letter is not digit then display error and don't type anything | |
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { | |
//display error message | |
$("#errmsg").html("Digits Only").show(); | |
return false; | |
} | |
}); | |
}); | |
#errmsg | |
{ | |
color: red; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment