Allow only numeric input in textbox using jQuery

HTML


<input type="text" name="numeric" class='allownumeric'>
<div>Numeric values only allowed</div>

jQuery


$(".allownumeric").keypress(function (event) {
 if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
 event.preventDefault();
 }
 });

working demo