onKeyDown ev.keycode

Hi,

I try to catch a keypressed on input, i do well, this if to avoid type only numbers or only letters.

    [b] [i] myForm.attachEvent("onKeyDown",function(inp, ev, name, value){	   
       console.log(ev.keyCode);  
      });[/i][/b]

if i only want numbers and i type strings, how can i set the keycode to 0 or the value typed set “”?

Sorry for my bad english

Thanks

Jose Rodriguez

Hi

sude you can attach onKeyDown event and call ev.preventDefault(); if ev.keyCode not matched to [48…57] for 0…9 digits, but there is also abolity to press ctrl+v or paste value with mouse right-click.

The better way is try to bring all cases to myForm.attachEvent(“onBeforeChange”) or myForm.attachEvent(“onChange”) logic.

Thank You so much Andrei!!! :smiley: