Fórum Validação de cpf #276431
10/04/2005
0
Galera bom dia negocio é o seguinte até o meu CPF q é 093.294.887-14 ta dando CPF invalido.
VEJA ABAIXO:
Uso Delphi 6 e Banco de Dados Interbase pois fui no Evento OnSetText do Fild e coloquei o seguinte Comando:
// VALIDAÇÃO DE CPF
procedure TDM.IBTClientesCPFSetText(Sender: TField; const Text: String);
var i, soma, D1, D2: integer;
CPF: string;
begin
if text = ´´ then
sender.AsString := ´´
else
if length(sender.AsString) <> 11 then
begin
showmessage(´CPF Inválido´);
abort;
end
else
begin
CPF := copy(Sender.AsString, 1, 9);
soma := 0;
for i := 1 to 9 do
soma := soma + (strtoint(copy(cpf, i, 1)) * (11 - i));
D1 := 11 - (soma mod 11);
if D1 >= 10 then
D1 := 0;
CPF := CPF + inttostr(D1);
soma := 0;
for i := 1 to 10 do
soma := soma + (strtoint(copy(cpf, i, 1)) * (12 - i));
D2 := 11 - (soma mod 11);
if D2 > 10 then
D2 := 0;
CPF := CPF + inttostr(D2);
if CPF <> Text then
begin
showmessage(´CPF Inválido´);
abort;
end
else
sender.AsString := text;
end;
end;
MAS COMO DISSE ACIMA ATÉ O MEU CPF DA DANDO INVÁLIDO
VEJA ABAIXO:
Uso Delphi 6 e Banco de Dados Interbase pois fui no Evento OnSetText do Fild e coloquei o seguinte Comando:
// VALIDAÇÃO DE CPF
procedure TDM.IBTClientesCPFSetText(Sender: TField; const Text: String);
var i, soma, D1, D2: integer;
CPF: string;
begin
if text = ´´ then
sender.AsString := ´´
else
if length(sender.AsString) <> 11 then
begin
showmessage(´CPF Inválido´);
abort;
end
else
begin
CPF := copy(Sender.AsString, 1, 9);
soma := 0;
for i := 1 to 9 do
soma := soma + (strtoint(copy(cpf, i, 1)) * (11 - i));
D1 := 11 - (soma mod 11);
if D1 >= 10 then
D1 := 0;
CPF := CPF + inttostr(D1);
soma := 0;
for i := 1 to 10 do
soma := soma + (strtoint(copy(cpf, i, 1)) * (12 - i));
D2 := 11 - (soma mod 11);
if D2 > 10 then
D2 := 0;
CPF := CPF + inttostr(D2);
if CPF <> Text then
begin
showmessage(´CPF Inválido´);
abort;
end
else
sender.AsString := text;
end;
end;
MAS COMO DISSE ACIMA ATÉ O MEU CPF DA DANDO INVÁLIDO
Spalenza
Curtir tópico
+ 0
Responder
Posts
10/04/2005
Marco Salles
[b:d8b84d1f9e]Sopinha [/b:d8b84d1f9e], v.c da dando[b:d8b84d1f9e] Sopa[/b:d8b84d1f9e].. Cuidado que podem usar seu Cpf para fazer compras na net :P :P :P :P :P
Brincadeiras a parte
Bem, eu nao entendi pq voce esta usando este evento
Geralmente Estas Validações são feitas no evento OnExit do campo
E outra , olhe a Seguinte instrução
No seu caso que o [b:d8b84d1f9e]Cpf é = 093.294.887-14[/b:d8b84d1f9e] o valor da variável Cpf sera = > 093.294.8 devido a presença dos[b:d8b84d1f9e] literais[/b:d8b84d1f9e]
:idea: Tire os literais e veja o que acontece...Passe somente [b:d8b84d1f9e]09329488714[/b:d8b84d1f9e]
Brincadeiras a parte
pois fui no Evento OnSetText do Fild e coloquei o seguinte Comando
: Bem, eu nao entendi pq voce esta usando este evento
Geralmente Estas Validações são feitas no evento OnExit do campo
E outra , olhe a Seguinte instrução
CPF := copy(Sender.AsString, 1, 9);
No seu caso que o [b:d8b84d1f9e]Cpf é = 093.294.887-14[/b:d8b84d1f9e] o valor da variável Cpf sera = > 093.294.8 devido a presença dos[b:d8b84d1f9e] literais[/b:d8b84d1f9e]
:idea: Tire os literais e veja o que acontece...Passe somente [b:d8b84d1f9e]09329488714[/b:d8b84d1f9e]
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)