<input type="text" class="test"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script> $('.test').keypress(function(e) { if (e.keyCode < 48 || e.keyCode > 57) { return false; } }); </script>