Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/06/2016, 11:41
Avatar de Juanelo666
Juanelo666
 
Fecha de Ingreso: septiembre-2014
Ubicación: México
Mensajes: 31
Antigüedad: 9 años, 8 meses
Puntos: 0
No duplicar caracter (-) en campo de texto

Buenas!
resulta que sobre mis input no se deben duplicar los caracteres (.) y (-) .

He logrado echarlo a andar con un script pero unicamente me respeta el caracter del (.)
y en mi peor caso nisiqueira me deja colocar el caracter (-)

la funcion que ocupo es la siguiente

Código Javascript:
Ver original
  1. function onKeyDecimal(e,thix) {
  2.         var keynum = window.event ? window.event.keyCode : e.which;
  3.         if (document.getElementById(thix.id).value.indexOf('.') != -1 && keynum == 46)
  4.             return false;      
  5.         if ((keynum == 8 || keynum == 48 || keynum == 46))
  6.             return true;
  7.         if (keynum <= 47 || keynum >= 58) return false;
  8.         return /\d/.test(String.fromCharCode(keynum));
  9.     }

claramente en los envetos de mis input mando a llamar esta funcion pero no me pinta ningun caracter (-).

Aqui mis input

Código HTML:
Ver original
  1. "<td>"
  2.            "Velocidad de Subida"
  3.          "</td>"
  4.          "<td>"
  5.             "<input id='txtvSubida' type='text' onkeypress='return onKeyDecimal(event,this)' maxlength='8'/> " + unidad
  6.           "</td>"
  7.          "</tr>"
  8.          "<tr align=left>"
  9.          "<td>"
  10.               "Velocidad de Bajada"
  11.          "</td>"
  12.          "<td>"
  13.            "<input id='txtvBajada' type='text' onkeypress='return onKeyDecimal(event,this)' maxlength='8'/> " + unidad
  14.          "</td>"

Por favor si alguien puede iluminar mi camino estaria agradecido eternamente