public boolean validaCpf(String cpf)
{
int soma = 0;
try {
Long.parseLong(cpf);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Somente n�meros s�o permitidos no CPF","ERRO",JOptionPane.ERROR_MESSAGE);
cpf.requestFocus();
return false;
}
if(cpf.length() == 11) {
for (int i=0; i < 9; i++)
soma += (10 - i) * (cpf.charAt(i) - '0');
soma = 11 - (soma % 11);
if (soma > 9) soma = 0;
if (soma == (cpf.charAt(9) - '0')) {
soma = 0;
for (int i=0; i < 10; i++)
soma += (11 - i) * (cpf.charAt(i) - '0');
soma = 11 - (soma % 11);
if (soma > 9) soma = 0;
if (soma == (cpf.charAt(10) - '0')) {
//JOptionPane.showMessageDialog(null,"CPF V�lido");
return true;
}
}
}
JOptionPane.showMessageDialog(null,"CPF Inv�lido","ERRO",JOptionPane.ERROR_MESSAGE);
return false;
}
Só que a linha:
cpf.requestFocus();
Está tendo erro, falta eu importar alguma biblioteca???? digitei algo errado?