Article View: chile.comp.programacion
Article #609Re: ayuda con validar rut
From: Rickoj
Date: Thu, 27 Mar 2008 01:52
Date: Thu, 27 Mar 2008 01:52
165 lines
4895 bytes
4895 bytes
ahahahah es ke lo del rut lo deje de ultimo arregle cosas mas importantes y
funciono asi (tenia mas cosas que hacer)
y salio todo bien, solo hubo errores de digitacion por lo del rut como 2
veces no mas
"catfart" <me@here.com> escribi� en el mensaje
news:frjvu5$4tf$1@news.nivel5.cl...
> wena llevai mas de una semana y con toda la ayuda todavia no lo sacas
>
>
> Rick_oj escribi�:
>> "Alberto Hormazabal C." <tuto@lj.cl> escribi� en el mensaje
>> news:47daed3c@news.vcd.cl...
>>> Rick_oj visito chile.comp.programacion y balbuceo:
>>>> baje ese de ahi, y no me funciono
>>>> voy a revisar nuevamente
>>> tengo un par de funciones en js pa validar rut, pero no me acuerdo cual
>>> de las 2
>>> es la que funciona bien bien.
>>> te dejo otras utiles tambienb
>>>
>>> ojala te sirvan
>>>
>>> :)
>>
>>
>> vale te aviso cual me funciono gracias
>>
>>
>>
>>>
>>>
>>> Validador de Rut 1
>>> ==================
>>> function validaRut(rut)
>>> {
>>> var rutlimpio = "";
>>> for (i=0; i < rut.length; i++){
>>> if ((rut.charAt(i)!=".") && (rut.charAt(i)!="-"))
>>> rutlimpio= rutlimpio + rut.charAt(i);
>>> }
>>> rut=rutlimpio;
>>> var drut=rut.charAt((rut.length-1));
>>> var dvr='0'
>>> suma=0
>>> mul=2
>>> for (i=rut.length -2 ; i >= 0; i--){
>>> 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 != drut.toLowerCase())){
>>> //alert("El RUT ingresado no es v�lido.");
>>> return false;
>>> }
>>> return true;
>>> }
>>>
>>>
>>> Validador Rut 2
>>> ===============
>>> function esRutValido(rut)
>>> {
>>> if(rut.length < 2) return false;
>>>
>>> digito=rut.charAt(rut.length-1).toUpperCase();
>>> cuerpo=rut.substr(0,rut.length-1);
>>>
>>> intSuma = 0
>>> intFactor = 2
>>> for (i= (cuerpo.length - 1) ; i >= 0; i--)
>>> {
>>> intSuma = intSuma + cuerpo.charAt(i) * intFactor
>>> if (intFactor == 7)
>>> intFactor = 2
>>> else
>>> intFactor++
>>> }
>>> intResto = intSuma % 11
>>> if (intResto == 1)
>>> dvr = 'K'
>>> else if (intResto == 0)
>>> dvr = '0'
>>> else
>>> {
>>> dvi = 11 - intResto
>>> dvr = dvi + ""
>>> }
>>> if(dvr == digito)
>>> {
>>> return true;
>>> }
>>> else
>>> {
>>> return false;
>>> }
>>> }
>>>
>>>
>>>
>>> Otras funciones para RUT
>>> ========================
>>>
>>>
>>> // Desformatea un rut de la forma nnn.nnn.nnn-k
>>> // a la forma nnnnnnnnnk
>>> // acepta tanto puntos, comas, guiones como
>>> // cualquier otro caracter como separador de
>>> // miles y de digito verificador.
>>> function decodeRut(s)
>>> {
>>> var rut = "";
>>> for(i=0;i<s.length;i++)
>>> {
>>> a=s.charAt(i);
>>> if( (a>='0' && a<='9') || a=='k' || a=='K' )
>>> rut=rut+a;
>>> }
>>> return rut;
>>> }
>>>
>>>
>>>
>>> // Agrega el caracter <separador> como
>>> // separador de miles en el numero <nStr>
>>> function formatNumber(nStr,separador)
>>> {
>>> nStr += '';
>>> x = nStr.split('.');
>>> x1 = x[0];
>>> x2 = x.length > 1 ? '.' + x[1] : '';
>>> var rgx = /(\d+)(\d{3})/;
>>> while (rgx.test(x1)) {
>>> x1 = x1.replace(rgx, '$1' + separador + '$2');
>>> }
>>> return x1 + x2;
>>> }
>>>
>>> // Convierte un rut de la forma nnnnnnnnnk a
>>> // la forma nnn.nnn.nnn-k
>>> function toRut(s)
>>> {
>>> var dv;
>>> var len;
>>> len = s.length;
>>> dv=s.substr(len-1,1);
>>> return ( formatNumber(s.substr(0,len-1),'.') + "-" + dv );
>>> }
>>> --
>>> El Tuto
>>> tuto@aalc.lj.cl
>>>
>>
Technical Details
Message-ID:
<fser4c$9da$1@news.nivel5.cl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news.kjsl.com!news.nivel5.cl!not-for-mailReferences:
<fqq6gv$uj2$1@news.nivel5.cl> <fr62f0$80a$1@news.nivel5.cl> <fr7ao1$d1s$1@news.nivel5.cl> <fr7eq4$diq$1@news.nivel5.cl> <fr7feh$dm2$1@news.nivel5.cl> <fr8mbi$hh0$1@news.nivel5.cl> <47daed3c@news.vcd.cl> <frhnof$g2h$1@news.nivel5.cl> <frjvu5$4tf$1@news.nivel5.cl>Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,80adbb2b571c3e5b X-Google-Attributes: gid1593cb,domainid0,public,usenet X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news.kjsl.com!news.nivel5.cl!not-for-mail From: "Rick_oj" <rick_oj[sin-esto]@tutopia.com> Newsgroups: chile.comp.programacion Subject: Re: ayuda con validar rut Date: Wed, 26 Mar 2008 21:52:22 -0400 Organization: Varios Lines: 166 Message-ID: <fser4c$9da$1@news.nivel5.cl> References: <fqq6gv$uj2$1@news.nivel5.cl> <fr62f0$80a$1@news.nivel5.cl> <fr7ao1$d1s$1@news.nivel5.cl> <fr7eq4$diq$1@news.nivel5.cl> <fr7feh$dm2$1@news.nivel5.cl> <fr8mbi$hh0$1@news.nivel5.cl> <47daed3c@news.vcd.cl> <frhnof$g2h$1@news.nivel5.cl> <frjvu5$4tf$1@news.nivel5.cl> NNTP-Posting-Host: 190.160.69.202 X-Trace: news.nivel5.cl 1206579149 9642 190.160.69.202 (27 Mar 2008 00:52:29 GMT) X-Complaints-To: news@news.nivel5.cl NNTP-Posting-Date: Thu, 27 Mar 2008 00:52:29 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198