mercoledì 27 febbraio 2013

Jquery - inserimento solo di alcuni caratteri dalla tastiera

$("#inputbox").live('keydown', function(e) {
           
  var key = String.fromCharCode(e.keyCode);
                        
  if (e.keyCode >96 && e.keyCode<105) return e.keyCode; 
  // per prendere anche la tastiera numerica
  if (e.which == 65)  {return e.keyCode; } // prende la a minuscola
  if (e.which == 66)  {return e.keyCode; } // prende la b minuscola
  if (e.which == 88)  {return e.keyCode; } // prende la x minuscola
  if (e.which == 89)  {return e.keyCode; } // prende  la y minuscola
                        
  if (isNaN(key)) return false;  // altri tasti che non siano numeri
                         
   if (   e.shiftKey /* Shift */
       || e.which == 9 /* Tab */
       || e.which == 32 /* barra spazio */
       || e.which == 27 /* Escape Key */
       || e.which == 17 /* Control Key */
       || e.which == 91 /* Windows Command Key */
       || e.which == 19 /* Pause Break */
       || e.altKey /* Alt Key */
       || e.which == 93 /* Right Click Point Key */
       || ( e.which >= 35 && e.which <= 40 ) /* Home, End, Arrow Keys */
       || e.which == 45) /* Insert Key */  
      { 
             return false;
        }
  });

Nessun commento:

Posta un commento