Introduction
This tutorial explains how to only allow a number in textbox using jQuery. If you simply add the 'numberonly' class to the text control, then it will only allow numbers.
Code
  1. $(document).ready(function () {
  2. $('.numberonly').keypress(function (e) {
  3. var charCode = (e.which) ? e.which : event.keyCode
  4. if (String.fromCharCode(charCode).match(/[^0-9]/g))
  5. return false;
  6. });
  7. });