Foros del Web » Programando para Internet » PHP »

Ayuda para Ingresar RUT con punto y guion

Estas en el tema de Ayuda para Ingresar RUT con punto y guion en el foro de PHP en Foros del Web. Hola bueno necesito un input que al ingresar por ejemplo 13483431k y al apretar el tab o al alirte d ese campo se autorellene asi: ...
  #1 (permalink)  
Antiguo 23/12/2007, 09:45
 
Fecha de Ingreso: diciembre-2007
Mensajes: 15
Antigüedad: 16 años, 4 meses
Puntos: 0
Ayuda para Ingresar RUT con punto y guion

Hola bueno necesito un input que al ingresar por ejemplo
13483431k
y al apretar el tab o al alirte d ese campo se autorellene asi:
13.483.431-k
en la pagina del banco http://www.bdd.cl/ tiene ese sistema al ingresar el rut y uno al apretar el TAB lo autorellena

Ojala alguien me pueda ayudar porque e buscado mil formas para hacerlo y todavia no pasa nada.

De Antemanos Muchas Gracias :)
  #2 (permalink)  
Antiguo 23/12/2007, 09:47
 
Fecha de Ingreso: noviembre-2002
Mensajes: 1.341
Antigüedad: 21 años, 5 meses
Puntos: 17
Re: Ayuda para Ingresar RUT con punto y guion

Eso se haría con Javascript, ya que PHP requiere enviar y recibir datos del servidor.

En tu caso no creo que fuera muy dificil. Tendrías que comprobar la longitud del campo, que sean todo números menos el último dígito y luego formatear el número.

Pero ya te digo que eso es javascript.
  #3 (permalink)  
Antiguo 23/12/2007, 10:01
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Re: Ayuda para Ingresar RUT con punto y guion

Hola o2kr

Como te dice Keysher, tendrás que usar JavaScript. Esto te puede servir:

Código:
<input type="text" onblur = "this.value = this.value.replace( /^(\d{2})(\d{3})(\d{3})(\w{1})$/, '$1-$2-$3-$4')" />
Saludos,
  #4 (permalink)  
Antiguo 23/12/2007, 13:25
 
Fecha de Ingreso: abril-2006
Mensajes: 240
Antigüedad: 18 años
Puntos: 1
Re: Ayuda para Ingresar RUT con punto y guion

hola ese script ya existe y es el sgte:

Código PHP:
function revisarDigito(dvr){    
  
dv dvr ""    
  
if( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K'){        
    
alert("Debe ingresar un digito verificador valido");        
    
window.document.form1.rutContacto.focus();        
    
window.document.form1.rutContacto.select();        
    return 
false;    
  }    
  return 
true;
}

function 
revisarDigito2(crut){    
  
largo crut.length;    
  if(
largo<2){        
    
alert("Debe ingresar el rut completo")        
    
window.document.form1.rutContacto.focus();        
    
window.document.form1.rutContacto.select();        
    return 
false;    
  }    
  if(
largo>2)        
    
rut crut.substring(0largo 1);    
  else        
    
rut crut.charAt(0);    
    
dv crut.charAt(largo-1);    
    
revisarDigitodv );    

  if ( 
rut == null || dv == null )
    return 
0    
    
var dvr '0'    
    
suma 0    
    mul  
2    

    
for (irut.length ->= 0i--){    
        
suma suma rut.charAt(i) * mul        
        
if (mul == 7)            
            
mul 2        
        
else                
            
mul++    
    }    
    
res suma 11    
    
if (res==1)        
        
dvr 'k'    
    
else if (res==0)        
        
dvr '0'    
    
else    
    {        
        
dvi 11-res        
        dvr 
dvi ""    
    
}
    if ( 
dvr != dv.toLowerCase() )    
    {        
        
alert("EL rut es incorrecto")        
        
window.document.form1.rutContacto.focus();        
        
window.document.form1.rutContacto.select();        
        return 
false    
    
}

    return 
true
}

function 
Rut(texto){    
  var 
tmpstr "";    
  for ( 
i=0texto.length i++ )        
    if ( 
texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
        
tmpstr tmpstr texto.charAt(i);    
    
texto tmpstr;    
    
largo texto.length;    

    if ( 
largo ){        
        
alert("Debe ingresar el rut completo")        
        
window.document.form1.rutContacto.focus();        
        
window.document.form1.rutContacto.select();        
        return 
false;    
    }    

    for (
i=0largo i++ ){            
        if ( 
texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" ){            
            
alert("El valor ingresado no corresponde a un R.U.T valido");            
            
window.document.form1.rutContacto.focus();            
            
window.document.form1.rutContacto.select();            
            return 
false;        
        }    
    }    

    var 
invertido "";    
    for ( 
i=(largo-1),j=0i>=0i--,j++ )        
        
invertido invertido texto.charAt(i);    
    var 
dtexto "";    
    
dtexto dtexto invertido.charAt(0);    
    
dtexto dtexto '-';    
    
cnt 0;    

    for ( 
i=1,j=2i<largoi++,j++ ){        
        
//alert("i=[" + i + "] j=[" + j +"]" );        
        
if ( cnt == ){            
            
dtexto dtexto '.';            
            
j++;            
            
dtexto dtexto invertido.charAt(i);            
            
cnt 1;        
        }else{                
           
dtexto dtexto invertido.charAt(i);            
           
cnt++;        
        }    
    }    

    
invertido "";    
    for ( 
i=(dtexto.length-1),j=0i>=0i--,j++ )        
        
invertido invertido dtexto.charAt(i);    

    
window.document.form1.rutContacto.value invertido.toUpperCase()        

    if(
revisarDigito2(texto))        
        return 
true;    
    return 
false;


tiene k editar donde sale document.form1.rutContacto.value con tus respectivos datos de tu form y lo usas de la sgte manera ewn tu form

Código PHP:
<input type="text" name="rutContacto" id="rutContacto" onblur="return Rut(form1.rutContacto.value)" /> 
salu2
  #5 (permalink)  
Antiguo 23/12/2007, 19:21
 
Fecha de Ingreso: diciembre-2007
Mensajes: 15
Antigüedad: 16 años, 4 meses
Puntos: 0
Re: Ayuda para Ingresar RUT con punto y guion

Muchas Gracias Problema RESUELTO :)
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado

SíEste tema le ha gustado a 1 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 10:12.