Aceitar somente números
Olá pessoal, beleza?
Seguinte, tenho q permitir q o usuário digite somente números em um campo.
Estou fazendo o seguinte...
function numero(e) { if (window.event) //IE { tecla = e.keyCode; } else if (e.which) //FF { tecla = e.which; } if (tecla != 8 || tecla < 48 || tecla > 57) return ((tecla > 47) && (tecla < 58)) //Aceita de 48 à 57 (números) { return true; } }
no htm fica assim..
<input........ onkeypress="return numero(event)" />
No IE funciona normalmente, mas no FF caso o usuário digite errado, não dá pra apagar...
Oq está errado no JS? No FF é (e.which) mesmo?
Obrigado.
[]'s
Daniel Carneiro
Discussão (4)
Carregando comentários...