Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/01/2015, 09:41
Avatar de vidalsoft
vidalsoft
 
Fecha de Ingreso: julio-2008
Ubicación: /www/...
Mensajes: 339
Antigüedad: 15 años, 9 meses
Puntos: 1
Respuesta: Permitir sólo números después del guión

Gracias amigo, pero funciona bien en consola. Pero no funciona cuando lo pongo dentro del keypress.

Que puede estar pasando?

Este es mi código:
Código Javascript:
Ver original
  1. $(document).ready(function (e) {
  2.             $('#txtNombreTelefono').bind('keypress', function (e) {
  3.                 if ($("#cboTipoConsulta").val() == "6" || $("#cboTipoConsulta").val() == "7" || $("#cboTipoConsulta").val() == "8") {
  4.                     if (e.which === 32) {
  5.                         e.preventDefault();
  6.                         return false;
  7.                     } else {
  8.                         var regex = new RegExp("^[a-zA-Z0-9]{1,4}(-)+[0-9]{1,12}$");
  9.                         var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
  10.                         if (!regex.test(key)) {                        
  11.                             e.preventDefault();
  12.                             return false;
  13.                         }
  14.                     }
  15.                     return true;
  16.                 }
  17.             }).blur(function () {
  18.                 $(this).val(function (i, oldVal) {
  19.                     return oldVal.replace(/\s/g, '');
  20.                 });
  21.             });
  22.         });
__________________
Anthony Vidal Contreras | @AnthonyVidalC | Skype: vidalsystem | [email protected]