Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/01/2010, 03:01
Avatar de ceSharp
ceSharp
 
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 495
Antigüedad: 15 años, 6 meses
Puntos: 66
Respuesta: Expresion regular sin # y con maximo 4 numeros

hola jisravila,

te dejo aquí la típica función para validar el campo de texto con patrón añadiendo un control de cuantos números se han introducido; si ya hay cuatro en el campo de texto no deja escribir más:

-----------------------------------------------------

function f_Solo4Num(e)
{
var tecla;
tecla = (document.all) ? e.keyCode : e.which;
if(tecla == 8)
{return true;}
var patron;
patron = /^([A-Z]|Ñ|á|é|í|ó|ú|ñ|ü|\s)|([0-9])+$/;
var te;
te = String.fromCharCode(tecla);

var texto = document.getElementById('campo_texto').value;
var nums = 0;
var caracterNumero = new Number(te);
var topeNumeros = false;
if(!isNaN(caracterNumero))
{
for(i=0;i<texto.length;i++)
{
var nCaracter = new Number(texto.substring(i,i+1));
if(!isNaN(nCaracter))
nums += 1;
if(nums>3)
{topeNumeros = true;break;}
}
}
if(topeNumeros)
return false;
else
return patron.test(te);
}
-------------------------------------------------

prueba y nos cuentas.

salu2.