$(document).ready(function () { //on keypressed in textbox $("#age").keypress(function (e) { //if not numeric, then it don't let you type if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { //display error message $("#errmsg").html("Digits Only").show().fadeOut("slow"); return false; } }); });
Number : <input type="text" name="age" id="age" /> <span id="errmsg"></span>
#errmsg { color: red; }