Posted By

frujo on 04/24/11


Tagged


Versions (?)

Allow only digits, delete and backspace.


 / Published in: jQuery
 

  1. $('#selector').keydown(function(event) {
  2. if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode > 112 ) {
  3.  
  4. }
  5. else {
  6. if (event.keyCode < 95) {
  7. if (event.keyCode < 49 || event.keyCode > 57 ) {
  8. event.preventDefault();
  9. }
  10. }
  11. else {
  12. if (event.keyCode < 97 || event.keyCode > 105 ) {
  13. event.preventDefault();
  14. }
  15. }
  16. }
  17.  
  18. });

Report this snippet  

You need to login to post a comment.