How to Only Allow Numbers in a Text Box using jQuery.

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.     
  3.             $('.numberonly').keypress(function (e) {    
  4.     
  5.                 var charCode = (e.which) ? e.which : event.keyCode    
  6.     
  7.                 if (String.fromCharCode(charCode).match(/[^0-9]/g))    
  8.     
  9.                     return false;                        
  10.     
  11.             });    
  12.     
  13.         });   
  14.