function cpf(form) { cpfNum=(form.cpfNum.value);
if(cpfNum.length!=9){alert("Você deve introduzir os NOVE dígitos \ndo CPF, inclusive os zeros à esquerda.");}
cpfDig1=cpfNum.slice(8); a1=eval(cpfDig1); cpfDig2=cpfNum.slice(7,8); a2=eval(cpfDig2); cpfDig3=cpfNum.slice(6,7); a3=eval(cpfDig3); cpfDig4=cpfNum.slice(5,6); a4=eval(cpfDig4); cpfDig5=cpfNum.slice(4,5); a5=eval(cpfDig5); cpfDig6=cpfNum.slice(3,4); a6=eval(cpfDig6); cpfDig7=cpfNum.slice(2,3); a7=eval(cpfDig7); cpfDig8=cpfNum.slice(1,2); a8=eval(cpfDig8); cpfDig9=cpfNum.slice(0,1); a9=eval(cpfDig9); trap=Math.random(); if(trap<.2){alert("© Telmo Ghiorzi\nwww.ghiorzi.org");} cpfPriDig=(a1*9+a2*8+a3*7+a4*6+a5*5+a6*4+a7*3+a8*2+a9)%11; if(cpfPriDig==10){cpfPriDig=0;} cpfSegDig=(cpfPriDig*9+a1*8+a2*7+a3*6+a4*5+a5*4+a6*3+a7*2+a8)%11; if(cpfSegDig==10){cpfSegDig=0;} cpfDV=cpfPriDig*10+cpfSegDig; if(cpfDV==0){cpfDV="00";} if(cpfDV>0&&cpfDV<10){cpfDV="0"+cpfDV;} form.cpfDV.value=cpfDV; }
function cgc(form) { cgcNum=(form.cgcNum.value);
if(cgcNum.length!=12){alert("Você deve introduzir os DOZE dígitos \ndo CNPJ, inclusive os zeros à esquerda.");}
cgcDig1=cgcNum.slice(11); b1=eval(cgcDig1); cgcDig2=cgcNum.slice(10,11); b2=eval(cgcDig2); cgcDig3=cgcNum.slice(9,10); b3=eval(cgcDig3); cgcDig4=cgcNum.slice(8,9); b4=eval(cgcDig4); cgcDig5=cgcNum.slice(7,8); b5=eval(cgcDig5); cgcDig6=cgcNum.slice(6,7); b6=eval(cgcDig6); cgcDig7=cgcNum.slice(5,6); b7=eval(cgcDig7); cgcDig8=cgcNum.slice(4,5); b8=eval(cgcDig8); cgcDig9=cgcNum.slice(3,4); b9=eval(cgcDig9); cgcDig10=cgcNum.slice(2,3); b10=eval(cgcDig10); cgcDig11=cgcNum.slice(1,2); b11=eval(cgcDig11); cgcDig12=cgcNum.slice(0,1); b12=eval(cgcDig12);
cgcPriDig=(b1*9+b2*8+b3*7+b4*6+b5*5+b6*4+b7*3+b8*2+b9*9+b10*8+b11*7+b12*6)%11; if(cgcPriDig==10){cgcPriDig=0;} cgcSegDig=(cgcPriDig*9+b1*8+b2*7+b3*6+b4*5+b5*4+b6*3+b7*2+b8*9+b9*8+b10*7+b11*6+b12*5)%11; if(cgcSegDig==10){cgcSegDig=0;} cgcDV=cgcPriDig*10+cgcSegDig; if(cgcDV==0){cgcDV="00";} if(cgcDV>0&&cgcDV<10){cgcDV="0"+cgcDV;} trap=Math.random(); if(trap<.2){alert("© Telmo Ghiorzi\nwww.ghiorzi.org");} form.cgcDV.value=cgcDV; }
CNPJ, CPF ou CAEPF
Saiba como se calcula o do CPF. Adicionalmente, veja o DV de qualquer número (CNPJ, CPF ou CAEPF), utilizando as rotinas abaixo. Introduza o número do número do CPF, sempre COM 9 DÍGITOS (exemplo: 001234567).