CFLib.org – Common Function Library Project

IsRUT(rut)

Last updated January 09, 2002

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Returns True if the specified value and verifying digit constitute a valid RUT (government company number used by Chile). RUT numbers appear in the form xx.xxx.xxx-y or x.xxx.xxx-y where x represents digits 0-9 and y represents the verifying digit in the form 0-9|K.

Return Values:
Returns a Boolean.

Example:

<CFSET RUT="13.623.479-K">
<CFSET NUT="12.345.678-0">
<CFOUTPUT>
Is #RUT# a valid RUT? #YesNoFormat(IsRut(RUT))#<BR>
Is #NUT# a valid RUT? #YesNoFormat(IsRut(NUT))#<BR>
</CFOUTPUT>

Parameters:

Name Description Required
rut RUT you want to verify. Yes

Full UDF Source:

/**
 * Returns True if the specified value and verifying digit constitute a valid RUT (government company number used in Chile).
 * 
 * @param rut      RUT you want to verify. 
 * @return Returns a Boolean. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1, January 9, 2002 
 */
function isrut(rut) {
  var dig=right(rut,1);
  var largo=0;
  var suma=0;
  var factor=2;
  var digito=0;
  var i=0;
  var valor="";
  rut=ReplaceList(rut, ".,-", "");
  rut=Left(Rut, Len(Rut)-1);
  if (isNumeric(rut)){
    largo=len(rut);
    for (i=largo;  i gte 1; i=i-1){
      if (factor gt 7) {
        factor=2;
      }
      suma = suma + factor * int(mid(rut,i,1));
      factor = factor + 1;
    }

    digito = 11 - (suma mod 11);
    switch(digito) {
      case 10: {
        valor = "K";
        break;
      }
      case 11: {
        valor = "0";
        break;
      }    
      default: {
        valor = digito;
        break;
      }
    }

    if (Ucase(valor) eq Ucase(dig)){
      return true;
    }
    else {
      return false;
    }
  }
  else {
    return false;
  }
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson