Allow only digits, delete and backspace.


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.