Ver Mensaje Individual
  #9 (permalink)  
Antiguo 31/08/2009, 09:22
Avatar de Javier01
Javier01
 
Fecha de Ingreso: febrero-2008
Ubicación: Montevideo
Mensajes: 261
Antigüedad: 16 años, 2 meses
Puntos: 31
Respuesta: JS para Campo de texto que valide Horas

Buenas tardes! tal vez este codigo te siva!

Código codigo:
Ver original
  1. <html>
  2. </head>
  3. <script type="text/javascript">
  4.  
  5. function isNumberKey(evt,elem) {
  6.     var charCode = (evt.which) ? evt.which : event.keyCode;
  7.     if (charCode > 31 && (charCode < 44 || charCode > 57 || charCode==45 || charCode==46 || charCode==47)){
  8.         return false;
  9.     }
  10.     else{
  11.         var valor=elem.value;
  12.         var tamanio=elem.value.length
  13.         if (elem.value > 99){
  14.             elem.value=99 + ',9';
  15.             return false;
  16.         }
  17.         if(charCode == 44){
  18.             if(valor.indexOf(',') < 0){
  19.                 if (tamanio > 0 && tamanio < 3){
  20.                  return true;
  21.                 }
  22.                 else {
  23.                     return false;
  24.                 }
  25.             }
  26.             else{
  27.                 return false;
  28.             }
  29.         }
  30.     }
  31. }
  32.  
  33. </script>
  34. </head>
  35. <body>
  36. <form>
  37. <h1>Valida del 1 al 99,9</h1>
  38. <input type="text" name="numero" id= "numero" onKeypress="return isNumberKey(event,this)" maxlength="4" />
  39. </form>
  40. </body>
  41. </html>

No esta para nada "pulido", pero capas te sirve de algo.
suerte y saludos
__________________
Tomarse un tiempo para redactar correctamente la pregunta, utilizando los signos de puntuación adecuados, es ganar tiempo y calidad en la respuesta.