JQuery : Allow only numbers for Textfield with sample code

The below is the sample code in JQuery used for making Textfield only allow numeric values.

JQuery: 

$("input.form-text").keypress(function (event) {
  if ((event.which < 48 || event.which > 57) && (event.which != 0 && event.which != 8)) {
    event.preventDefault();
  }
});

 

Category: