Foros del Web » Programando para Internet » Javascript » Frameworks JS »

como llamar validar rut con esta clase validarut

Estas en el tema de como llamar validar rut con esta clase validarut en el foro de Frameworks JS en Foros del Web. Hola amigos les cuento encontre esta clase q valida rut con prototype esta es: Código: //Clase Valida RUT var RUT=Class.create(); RUT.prototype={ initialize:function(rut){ this.Orut=new String(rut); this.Dvs=new ...
  #1 (permalink)  
Antiguo 29/04/2009, 19:08
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
como llamar validar rut con esta clase validarut

Hola amigos les cuento encontre esta clase q valida rut con prototype esta es:
Código:
//Clase Valida RUT


var RUT=Class.create();

RUT.prototype={
   initialize:function(rut){
       this.Orut=new String(rut);
       this.Dvs=new String("123456789K0");
       this.error=false;
       this.nerror=-1;
       this.prepara()
       this.valFormato();
   },
   prepara:function(){
      var cr=this.Orut;
      if(cr!=""){
         cr=cr.replace(/[\.|\-|\s]+/g,"");
         this.rut=cr.substr(0,cr.length-1);
         this.dv=new String(cr.substr(cr.length-1,cr.length)).toUpperCase();
      }
      if(String(this.rut)=='undefined') this.rut="";
      if(String(this.dv)=='undefined') this.dv='-1';
      return this.rut;
   },
   clear:function(){ return this.rut; },
   valFormato:function(){
      if(this.rut.length==0){ this.error=true; return this.nerror=0; }
      if(this.rut.length!=String(parseInt(this.rut)).length){ this.error=true; return this.nerror=1; }
      if(this.Dvs.indexOf(this.dv)==-1){ this.error=true; return this.nerror=2; }
   },
   format:function(){
      this.prepara();
      var r=$A(new String(this.rut));
      var temp="";
      var c=0;
      r.each(function(v,i){
         temp+=r[r.length-(i+1)];
         if(((++c)<r.length) && (c%3)==0) temp+=".";
      });
      r=$A(temp);
      temp="";
      r.each(function(v,i){
         temp+=r[r.length-(i+1)];
      });
      return temp+"-"+this.dv;
   },
   Error:function(){
     return this.error
   },
   getNError:function(){
      return this.nerror;
   },
   getError:function(){
      if(this.nerror==-1) return "No se han identificado errores";
      var errores=new Array();
      errores[errores.length]="Ingrese Rut";
      errores[errores.length]="Rut '"+this.rut+"' contiene caracteres no validos";
      errores[errores.length]="Digito Verificador '"+this.dv+"' no es un caracter correcto";
      return errores[this.nerror];
   },
   getOriginal:function(){
      return this.Orut;
   },
   get:function(){
      return this.rut;
   },
   getDv:function(){
      if(this.error){ return -1; }
      var r=parseInt(this.rut);
      var m=1;
      var suma=0;
      do{
         suma+=(r%10)*(m=(m<7)?++m:2);
         r=parseInt(r/10);
      }while(r!=0);
      return this.Dvs.charAt(10-(suma%11));  
   },
   valida:function(){
      if(this.error){ return false; }
      return (this.getDv()==this.dv)?true:false;
   }
}
y lo q no se es como crear el objeto rut para validar el campo rut de mi form, he intentado de estas maneras:

var Rut=new RUT(rut_padre);
if(Rut.Error(rut_padre)){
alert(Rut.getError(rut_padre));
}
else{
if(Rut.valida(rut_padre)){
//Rut valido
alert ('rut valido');
}
else{
//Rut no valido
alert ('rut no valido');
}
}

donde rut_padre es el nombre del campo rut de mi form, obviamente estoy creando el objeto de la clase rut dentro de etiquetas javascript de la pagina donde tengo el campo de texto rut_padre y tb obviamente estoy llamando a la clase valida_rut q tengo en un archivo aparte, como les mostre anteriormente q lo estoy haciendo no me resulta, en la pagina desde donde baje la clase sale el ejemplo de como crear el objeto de la clase para comenzar a validar el rut esta manera es esta:

var Rut=new RUT('11111111-1');
if(Rut.Error()){
alert(Rut.getError());
}
else{
if(Rut.valida()){
//Rut valido
}
else{
//Rut no valido
}
}

lo probe pasando como parametro mi variable rut_padre, pero tampoco me funciona, ademas tengo el firebug pero este no me muestra ningun error :S porfavor amigos como tengo q crear el objeto de la clase valida_rut para poder validar los rut de mis form??? porfavor amigos agradeceria su ayuda un ejemplo una guia o lo q sea .... de antemano gracias....bye

PD: la pagina desde donde baje esta clase es:

http://emcijey.blogspot.com/2008/04/...alida-rut.html
  #2 (permalink)  
Antiguo 29/04/2009, 19:09
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: como llamar validar rut con esta clase validarut

Cita:
Iniciado por r0xdrig0 Ver Mensaje
Hola amigos les cuento encontre esta clase q valida rut con prototype esta es:
Código:
//Clase Valida RUT


var RUT=Class.create();

RUT.prototype={
   initialize:function(rut){
       this.Orut=new String(rut);
       this.Dvs=new String("123456789K0");
       this.error=false;
       this.nerror=-1;
       this.prepara()
       this.valFormato();
   },
   prepara:function(){
      var cr=this.Orut;
      if(cr!=""){
         cr=cr.replace(/[\.|\-|\s]+/g,"");
         this.rut=cr.substr(0,cr.length-1);
         this.dv=new String(cr.substr(cr.length-1,cr.length)).toUpperCase();
      }
      if(String(this.rut)=='undefined') this.rut="";
      if(String(this.dv)=='undefined') this.dv='-1';
      return this.rut;
   },
   clear:function(){ return this.rut; },
   valFormato:function(){
      if(this.rut.length==0){ this.error=true; return this.nerror=0; }
      if(this.rut.length!=String(parseInt(this.rut)).length){ this.error=true; return this.nerror=1; }
      if(this.Dvs.indexOf(this.dv)==-1){ this.error=true; return this.nerror=2; }
   },
   format:function(){
      this.prepara();
      var r=$A(new String(this.rut));
      var temp="";
      var c=0;
      r.each(function(v,i){
         temp+=r[r.length-(i+1)];
         if(((++c)<r.length) && (c%3)==0) temp+=".";
      });
      r=$A(temp);
      temp="";
      r.each(function(v,i){
         temp+=r[r.length-(i+1)];
      });
      return temp+"-"+this.dv;
   },
   Error:function(){
     return this.error
   },
   getNError:function(){
      return this.nerror;
   },
   getError:function(){
      if(this.nerror==-1) return "No se han identificado errores";
      var errores=new Array();
      errores[errores.length]="Ingrese Rut";
      errores[errores.length]="Rut '"+this.rut+"' contiene caracteres no validos";
      errores[errores.length]="Digito Verificador '"+this.dv+"' no es un caracter correcto";
      return errores[this.nerror];
   },
   getOriginal:function(){
      return this.Orut;
   },
   get:function(){
      return this.rut;
   },
   getDv:function(){
      if(this.error){ return -1; }
      var r=parseInt(this.rut);
      var m=1;
      var suma=0;
      do{
         suma+=(r%10)*(m=(m<7)?++m:2);
         r=parseInt(r/10);
      }while(r!=0);
      return this.Dvs.charAt(10-(suma%11));  
   },
   valida:function(){
      if(this.error){ return false; }
      return (this.getDv()==this.dv)?true:false;
   }
}
y lo q no se es como crear el objeto rut para validar el campo rut de mi form, he intentado de estas maneras:

var Rut=new RUT(rut_padre);
if(Rut.Error(rut_padre)){
alert(Rut.getError(rut_padre));
}
else{
if(Rut.valida(rut_padre)){
//Rut valido
alert ('rut valido');
}
else{
//Rut no valido
alert ('rut no valido');
}
}

donde rut_padre es el nombre del campo rut de mi form, obviamente estoy creando el objeto de la clase rut dentro de etiquetas javascript de la pagina donde tengo el campo de texto rut_padre y tb obviamente estoy llamando a la clase valida_rut q tengo en un archivo aparte, como les mostre anteriormente q lo estoy haciendo no me resulta, en la pagina desde donde baje la clase sale el ejemplo de como crear el objeto de la clase para comenzar a validar el rut esta manera es esta:

var Rut=new RUT('11111111-1');
if(Rut.Error()){
alert(Rut.getError());
}
else{
if(Rut.valida()){
//Rut valido
}
else{
//Rut no valido
}
}

lo probe pasando como parametro mi variable rut_padre, pero tampoco me funciona, ademas tengo el firebug pero este no me muestra ningun error :S porfavor amigos como tengo q crear el objeto de la clase valida_rut para poder validar los rut de mis form??? porfavor amigos agradeceria su ayuda un ejemplo una guia o lo q sea .... de antemano gracias....bye

PD: la pagina desde donde baje esta clase es:

http://emcijey.blogspot.com/2008/04/...alida-rut.html
la clase esta hecha en ajax prototype
  #3 (permalink)  
Antiguo 30/04/2009, 12:37
 
Fecha de Ingreso: marzo-2004
Ubicación: Chile
Mensajes: 382
Antigüedad: 20 años, 1 mes
Puntos: 0
Respuesta: como llamar validar rut con esta clase validarut

haber se muy poco del framework Protype y estoy decidido a aprender el framework jQuery ya que he leido mucho comentarios buenos.

Si por causalidad decides elejir este framework hay un plugin que valida y da formato al rut.

te dejo la direccion...si te interesa.

http://plugins.jquery.com/project/Rut

eso seria suerte.
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.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:43.