Ver Mensaje Individual
  #9 (permalink)  
Antiguo 17/01/2009, 04:08
Avatar de JavierB
JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 3 meses
Puntos: 772
Respuesta: Duda: textbox que acepte solo numeros

Hola de nuevo.

El código funciona bien. Prueba este ejemplo:

Código javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function validar(e) {
  5.     tecla = (document.all) ? e.keyCode : e.which;
  6.     if (tecla==8) return true;
  7.     patron =/\d/;
  8.     te = String.fromCharCode(tecla);
  9.     return patron.test(te);
  10. }
  11. </script>
  12. </head>
  13.  
  14. <body>
  15. <input type="text" name="textfield" onkeypress="return validar(event)" />
  16. </body>
  17. </html>

Saludos,