Thursday, September 20, 2012

jQuery numbers only on textbox

For input[type="text"] number only! 
jQuery(".button").keydown(function(event) {
 if ( event.keyCode == 46 || event.keyCode == 8 || 
event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||            
  (event.keyCode == 65 && event.ctrlKey === true) ||          
  (event.keyCode >= 35 && event.keyCode <= 39)){              
    return;// let it happen, don't do anything
 }
 else {
  if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && 
(event.keyCode < 96 || event.keyCode > 105 )) {
   event.preventDefault(); 
  }   
 }
});

1 comment:

  1. Bakla what is this all about? I don't understand this code.

    ReplyDelete