EasyCFM.COM ColdFusion Forums / PHP to CFML / validate numbers

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: validate numbers

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

IdefiX
09-06-2003 @ 10:52 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 92
Joined: Mar 2003

hi, is this too hard to convert to cf??


function validar_rut($rut,$digito_v){

if ($rut == ""){
    $verificado=false;
    return $verificado;
}

$x=2;
$sumatorio=0;
  for ($i=strlen($rut)-1;$i>=0;$i--){
     if ($x>7){$x=2;}
      $sumatorio=$sumatorio+($rut[$i]*$x);
      $x++;
  }
  $digito=$sumatorio%11;
  $digito=11-$digito;

   switch ($digito){
     case 10:
        $digito="k";
       break;
     case 11:
        $digito="0";
       break;
   }

  if (strtolower($digito_v)==$digito){
   $verificado=true;
   } else {
   $verificado=false;
  }

   return $verificado;
}

$rut="el_rut"; // aqui el RUT
$digito="digito_verificador"; // aqui el digito verificador.

if (validar_rut($rut,$digito)){
echo "RUT correcto";
}else{
echo "RUT no valido";
}


it can be easily done in JS, but don't know how to do it in cf

thanks in advance

------------------------------
I'm sick of all you hypocrites holding me at bay And I don't need your sympathy to get me through the day.
A Change Of Seasons.

http://www.chilebike.cl

xpresources
09-10-2003 @ 8:20 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 177
Joined: Feb 2003


<cfscript>
function validar_rut(rut,digito_v){

if (len(rut) LTE 0){
    verificado=false;
    return verificado;
}

x=     2;
sumatorio=     0;

for (i=len($rut)-1; i GTE 0; i-1){
     if (x GT 7){x=2;}
sumatorio= int(sumatorio + (rut*x);
      $x+1;
}
  digito= sumatorio%11;
  digito= 11-digito;

   switch (digito){
     case 10:
        digito="k";
       break;
     case 11:
        digito="0";
       break;
   }

  if (ucase(digito_v)== digito){
   verificado=true;
   } else {
   verificado=false;
  }

   return verificado;
}

rut="el_rut"; // aqui el RUT
digito="digito_verificador"; // aqui el digito verificador.

if (validar_rut(rut,digito)){
WriteOutput("RUT correcto");
}
else{
WriteOutput("RUT no valido");
}
</cfscript>


Work for you?

Drew Tempelmeyer
drew@drewtemp.com
http://www.xp-resources.com
http://www.drewtemp.com

IdefiX
09-11-2003 @ 10:38 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 92
Joined: Mar 2003

oh! dam i forgot... the code is in php
didn't add the <?php the_code ?>

sorry... ^_^

------------------------------
I'm sick of all you hypocrites holding me at bay And I don't need your sympathy to get me through the day.
A Change Of Seasons.

http://www.chilebike.cl

This message was edited by IdefiX on 9-11-03 @ 10:39 PM

IJoeR
11-03-2004 @ 2:54 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 9
Joined: Nov 2004

I think he new that it was in PHP, since the variables started with a "$"

I also think he converted it for you already into Coldfusion


Website Designed and Developed by Pablo Varando.