Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/04/2009, 14:39
r0xdrig0
 
Fecha de Ingreso: diciembre-2007
Mensajes: 385
Antigüedad: 16 años, 5 meses
Puntos: 0
Como llamar desde mi form a esta clase Rut.js hecha en prototype???

Hola amigos, encontre una clase en la web la cual me sirve para veificar un RUT (numero identificador unico para cada persona en Chile, seria como el DNI en España), el problema es q soy ultra novato en prototype y no se como llamarla desde mi form para utilizarla y verificar el RUT q tengo en mi form ¿Como hago para llamar esta clase y utilizarla para q me verifique el RUT en mi form? la clase es la siguiente:

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;
   }
}
esa es la clase q deseo/necesito implementar.... como hago para llamarla desde mi form y comenzar a utilizarla para la verificacion de RUT.... ruego su ayuda amigos.... de antemano gracias.... bye