Ver Mensaje Individual
  #5 (permalink)  
Antiguo 12/02/2013, 17:59
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 9 meses
Puntos: 1567
Respuesta: Bloqueo de tecla enter y anulacion de caracteres no validos y letras, admi

Si es para numeros enteros (no decimales)

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es-ar">
  3. <meta charset="utf-8" />
  4. <title>Aceptar solo número desde teclado</title>
  5. </head>
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. function validar(e){
  9. var expresion=/[\d]/;
  10. if(expresion.test(String.fromCharCode(e.which))){
  11. return expresion.test(String.fromCharCode(e.which));
  12. }else{
  13. alert('error');
  14. return false;
  15. }
  16. }
  17. //]]>
  18.  <input type="text" id="numero" name="numero" onkeypress="return validar(event)" />
  19. </body>
  20. </html>
Saludos)
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.