Usuário com melhor resposta
[jQuery] Como bloquear o uso de números para um INPUT?

Pergunta
-
Olá,
Preciso que o input aceite todos os caracteres, menos número.
Como faze-lo?
Atualmente com o uso do script abaixo, ele bloqueia números e permite caracteres. O problema é que ele bloqueia algumas teclas como tab, e isto não fica legal.
<script> $(document).ready(function () { $("input[id*='input']").keypress(function (e) { var charCode = (e.which) ? e.which : e.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } }); }); </script>
Obrigado
[Este fórum já foi muito bom, saudades.]
- Editado TI DEV segunda-feira, 6 de agosto de 2018 17:22
Respostas
-
Olá,
Conforme este link, segue resposta:
Nome: <input type="text" onkeypress="return Onlychars(event)"> Telefone: <input type="text" onkeypress="return Onlynumbers(event)"> -- <script> function Onlynumbers(e) { var tecla=new Number(); if(window.event) { tecla = e.keyCode; } else if(e.which) { tecla = e.which; } else { return true; } if((tecla >= "97") && (tecla <= "122")){ return false; } } function Onlychars(e) { var tecla=new Number(); if(window.event) { tecla = e.keyCode; } else if(e.which) { tecla = e.which; } else { return true; } if((tecla >= "48") && (tecla <= "57")){ return false; } } </script>
Basta usar a função Onlychars.
Valeuuuus
[Este fórum já foi muito bom, saudades.]
- Marcado como Resposta TI DEV terça-feira, 7 de agosto de 2018 01:32
Todas as Respostas
-
-
-
Olá,
Conforme este link, segue resposta:
Nome: <input type="text" onkeypress="return Onlychars(event)"> Telefone: <input type="text" onkeypress="return Onlynumbers(event)"> -- <script> function Onlynumbers(e) { var tecla=new Number(); if(window.event) { tecla = e.keyCode; } else if(e.which) { tecla = e.which; } else { return true; } if((tecla >= "97") && (tecla <= "122")){ return false; } } function Onlychars(e) { var tecla=new Number(); if(window.event) { tecla = e.keyCode; } else if(e.which) { tecla = e.which; } else { return true; } if((tecla >= "48") && (tecla <= "57")){ return false; } } </script>
Basta usar a função Onlychars.
Valeuuuus
[Este fórum já foi muito bom, saudades.]
- Marcado como Resposta TI DEV terça-feira, 7 de agosto de 2018 01:32