Ver Mensaje Individual
  #6 (permalink)  
Antiguo 14/08/2009, 13:40
Avatar de kaninox
kaninox
 
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 19 años, 5 meses
Puntos: 49
Respuesta: Codigo Para Validar RUT Chileno!

te dejo algo mas completo ;)

http://www.andrade.cl/labs/rut.php

Lo vamos a dejar aquí por si se cae la web uno nunca sabe, y despues alguien busca ;)

Código php:
Ver original
  1. <?php
  2. function validaRut($rut){
  3.     if(strpos($rut,"-")==false){
  4.         $RUT[0] = substr($rut, 0, -1);
  5.         $RUT[1] = substr($rut, -1);
  6.     }else{
  7.         $RUT = explode("-", trim($rut));
  8.     }
  9.     $elRut = str_replace(".", "", trim($RUT[0]));
  10.     $factor = 2;
  11.     for($i = strlen($elRut)-1; $i >= 0; $i--):
  12.         $factor = $factor > 7 ? 2 : $factor;
  13.         $suma += $elRut{$i}*$factor++;
  14.     endfor;
  15.     $resto = $suma &#37; 11;
  16.    $dv = 11 - $resto;
  17.     if($dv == 11){
  18.         $dv=0;
  19.     }else if($dv == 10){
  20.         $dv="k";
  21.     }else{
  22.         $dv=$dv;
  23.     }
  24.    if($dv == trim(strtolower($RUT[1]))){
  25.        return true;
  26.    }else{
  27.        return false;
  28.    }
  29. }
  30.  
  31. ?>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34.     <head>
  35.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  36.         <title></title>
  37.     </head>
  38.     <body>
  39.        <form method="post" action="">
  40. <label for="rut">Ingresa tu RUT para validar</label>
  41. <input name="rut" value="" type="text" />
  42. <input type="submit" value="probar" />
  43. </form>
  44. <div>
  45. <?php
  46. if($_POST['rut']){
  47.     if(validaRut($_POST['rut'])==true){
  48.         echo "El rut ".$_POST['rut']." es v&aacute;lido";
  49.     }else{
  50.          echo "El rut ".$_POST['rut']." no es incorrecto";
  51.     }
  52. }
  53. ?>
  54. </div>
__________________
Gokuh Salvo al mundo. PUNTO!!!!