juancarlos
New Member
Hi,
i have a element called "rut" (Without " "). I need validate that this element with this code. So i create a validation php in element rut, i use return true; like conditi?n and this code.
I only change the var $rut for $data.
Any help? Thank you very much for the help
i have a element called "rut" (Without " "). I need validate that this element with this code. So i create a validation php in element rut, i use return true; like conditi?n and this code.
PHP:
function validaRut($rut){
if(strpos($rut,"-")==false){
$RUT[0] = substr($rut, 0, -1);
$RUT[1] = substr($rut, -1);
}else{
$RUT = explode("-", trim($rut));
}
$elRut = str_replace(".", "", trim($RUT[0]));
$factor = 2;
for($i = strlen($elRut)-1; $i >= 0; $i--):
$factor = $factor > 7 ? 2 : $factor;
$suma += $elRut{$i}*$factor++;
endfor;
$resto = $suma % 11;
$dv = 11 - $resto;
if($dv == 11){
$dv=0;
}else if($dv == 10){
$dv="k";
}else{
$dv=$dv;
}
if($dv == trim(strtolower($RUT[1]))){
return true;
}else{
return false;
}
}
I only change the var $rut for $data.
Any help? Thank you very much for the help