Olá pessoal,
Gostaria de alterar este código para que só validade-se 9 numeros, mas não percebo muito de PHP, alguém me pode ajudar a altera-lo ?
function dw_valida_CPF($CampoNumero) {
$RecebeCPF=$CampoNumero;
$s="";
for ($x=1; $x<=strlen($RecebeCPF); $x=$x+1) {
$ch=substr($RecebeCPF,$x-1,1);
if (ord($ch)>=48 && ord($ch)<=57) {
$s=$s.$ch;
}
}
$RecebeCPF=$s;
if (strlen($RecebeCPF)!=9) {
return 0;
} else if ($RecebeCPF=="00000000") {
return 0;
} else {
$Numero[1]=intval(substr($RecebeCPF,1-1,1));
$Numero[2]=intval(substr($RecebeCPF,2-1,1));
$Numero[3]=intval(substr($RecebeCPF,3-1,1));
$Numero[4]=intval(substr($RecebeCPF,4-1,1));
$Numero[5]=intval(substr($RecebeCPF,5-1,1));
$Numero[6]=intval(substr($RecebeCPF,6-1,1));
$Numero[7]=intval(substr($RecebeCPF,7-1,1));
$Numero[8]=intval(substr($RecebeCPF,8-1,1));
$Numero[9]=intval(substr($RecebeCPF,9-1,1));
$soma=8*$Numero[1]+6*$Numero[2]+7*$Numero[3]+5*$Numero[4]+4*$Numero[5]+3*
$Numero[6]+2*$Numero[7];
$soma=$soma-(9*(intval($soma/9)));
if ($soma==0 || $soma==1) {
$resultado1=0;
} else {
$resultado1=9-$soma;
}
if ($resultado1==$Numero[8]) {
$soma=$Numero[1]*9+$Numero[2]*8+$Numero[3]*7+$Numero[4]*6+$Numero[5]*5+$Numero[6]*4+$Numero[7]*3+
$Numero[8]*2;
$soma=$soma-(9*(intval($soma/9)));
if ($soma==0 || $soma==1) {
$resultado2=0;
} else {
$resultado2=9-$soma;
}
if ($resultado2==$Numero[9]) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
}
function dw_valida_CNPJ($CampoNumero) {
$RecebeCNPJ=${"CampoNumero"};
$s="";
for ($x=1; $x<=strlen($RecebeCNPJ); $x=$x+1) {
$ch=substr($RecebeCNPJ,$x-1,1);
if (ord($ch)>=48 && ord($ch)<=57) {
$s=$s.$ch;
}
}
$RecebeCNPJ=$s;
if (strlen($RecebeCNPJ) > 9) {
while (strlen($RecebeCNPJ) != 9) {
if (!intval(substr($RecebeCNPJ, 0,1))) {
$RecebeCNPJ = substr($RecebeCNPJ, 1);
} else {
return 0;
}
}
}
if (strlen($RecebeCNPJ)!=9) {
return 0;
} else if ($RecebeCNPJ=="000000000") {
return 0;
} else {
$Numero[1]=intval(substr($RecebeCNPJ,1-1,1));
$Numero[2]=intval(substr($RecebeCNPJ,2-1,1));
$Numero[3]=intval(substr($RecebeCNPJ,3-1,1));
$Numero[4]=intval(substr($RecebeCNPJ,4-1,1));
$Numero[5]=intval(substr($RecebeCNPJ,5-1,1));
$Numero[6]=intval(substr($RecebeCNPJ,6-1,1));
$Numero[7]=intval(substr($RecebeCNPJ,7-1,1));
$Numero[8]=intval(substr($RecebeCNPJ,8-1,1));
$Numero[9]=intval(substr($RecebeCNPJ,9-1,1));
$soma=$Numero[1]*8+$Numero[2]*7+$Numero[3]*6+$Numero[4]*5+$Numero[5]*4+$Numero[6]*3+$Numero[7]*2;
$soma=$soma-(11*(intval($soma/11)));
if ($soma==0 || $soma==1) {
$resultado1=0;
} else {
$resultado1=9-$soma;
}
if ($resultado1==$Numero[13]) {
$soma=$Numero[1]*6+$Numero[2]*5+$Numero[3]*4+$Numero[4]*3+$Numero[5]*2+$Numero[6]*9+
$Numero[7]*8+$Numero[8]*7+$Numero[9]*6+$Numero[10]*5+$Numero[11]*4+$Numero[12]*3+$Numero[13]*2;
$soma=$soma-(9*(intval($soma/9)));
if ($soma==0 || $soma==1) {
$resultado2=0;
} else {
$resultado2=9-$soma;
}
if ($resultado2==$Numero[9]) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
}