uso com MaskEdit: soh libera sem preencher e com preenchimento tudo zero...
Function ValidaCPF(CPF:String) :Boolean; Const TAM_CPF = 11; Var i, Aux: Integer; Str: String; Begin Result := True; Aux := 0; For i := 1 To Length(CPF) Do If CPF[i] = ' ' Then Aux := Aux + 1; If (Aux <> 0) And (Aux <> 11) Then Begin Result := False; Exit End Else If CPF = ' . . - ' Then Exit; For i := 1 To Length(Trim(CPF)) Do If (CPF[i] In ['0'..'9']) Then Str := Str+CPF[i]; CPF := StringOfChar('0',TAM_CPF-Length(Str))+Str; Aux := 0; For i := 2 To 10 Do Aux := Aux+(StrToInt(Copy(CPF,11-i,1))*i) ; Aux := Aux*10; Aux := (Aux Mod 11); If Aux = 10 Then Aux := 0; If StrToInt(Copy(CPF,10,1)) = Aux Then Begin Aux := Aux*2; For i := 3 To 11 Do Aux := Aux+(StrToInt(Copy(CPF,12-i,1))*i); Aux := Aux*10; Aux := (Aux Mod 11); If Aux = 10 Then Aux := 0; Result := (StrToInt(Copy(CPF,11,1)) = Aux); End Else Result := False; For i := 2 To Length(CPF) Do If CPF[i] <> CPF[i-1] Then Break; If (CPF[1] <> '0') And (i = 12) Then Result := False; End; Function ValidaCGC(CGC: String) :Boolean; Const TAM_CGC = 14; Var i, Aux: Integer; Str: String; Begin Result := True; Aux := 0; For i := 1 To Length(CGC) Do If CGC[i] = ' ' Then Aux := Aux + 1; If (Aux <> 0) And (Aux <> 14) Then Begin Result := False; Exit End Else If CGC = ' . . / - ' Then Exit; For i := 1 To Length(Trim(CGC)) Do If (CGC[i] In ['0'..'9']) Then Str := Str+CGC[i]; CGC := StringOfChar('0',TAM_CGC-Length(Str))+Str; Aux := 0; For i := 2 To 9 Do Aux := Aux + ((StrToInt(Copy(CGC,14-i,1)))*i); For i := 2 To 5 Do Aux := Aux + ((StrToInt(Copy(CGC, 6-i,1)))*i); Aux := Aux*10; Aux := (Aux Mod 11); If Aux = 10 Then Aux := 0; If StrToInt(Copy(CGC,13,1)) = Aux Then Begin Aux := Aux*2; For i := 3 To 9 Do Aux := Aux + (StrToInt(Copy(CGC,15-i,1))*i); For i := 2 To 6 Do Aux := Aux + (StrToInt(Copy(CGC, 7-i,1))*i); Aux := Aux*10; Aux := (Aux Mod 11); If Aux = 10 Then Aux := 0; Result := (StrToInt(Copy(CGC,14,1)) = Aux); End Else Result := False; For i := 2 To Length(CGC) Do If CGC[i] <> CGC[i-1] Then Break; If (CGC[1] <> '0') And (i = 15) Then Result := False; End; Leandro... [> Mutuka <] ----- Mensagem original ---- De: Paulo Yahoo <[EMAIL PROTECTED]> Para: delphi-br@yahoogrupos.com.br Enviadas: Sexta-feira, 1 de Dezembro de 2006 17:54:26 Assunto: Re: [delphi-br] VERIFICADOR CNPJ Régis, eu uso assim, talvez tenha coisa melhor. Paulo function TForm_PRINCIPAL. CPF(num: string): boolean; var n1,n2,n3,n4, n5,n6,n7, n8,n9: integer; d1,d2: integer; digitado, calculado: string; Confere:boolean; begin Confere:=True; Try n1:=StrToInt( num[1]) Except Confere:=False end; Try n2:=StrToInt( num[2]) Except Confere:=False end; Try n3:=StrToInt( num[3]) Except Confere:=False end; Try n4:=StrToInt( num[4]) Except Confere:=False end; Try n5:=StrToInt( num[5]) Except Confere:=False end; Try n6:=StrToInt( num[6]) Except Confere:=False end; Try n7:=StrToInt( num[7]) Except Confere:=False end; Try n8:=StrToInt( num[8]) Except Confere:=False end; Try n9:=StrToInt( num[9]) Except Confere:=False end; If Confere=True then begin d1:=n9*2+n8* 3+n7*4+n6* 5+n5*6+n4* 7+n3*8+n2* 9+n1*10; d1:=11-(d1 mod 11); If d1>=10 then d1:=0; d2:=d1*2+n9* 3+n8*4+n7* 5+n6*6+n5* 7+n4*8+n3* 9+n2*10+n1* 11; d2:=11-(d2 mod 11); If d2>=10 then d2:=0; calculado:=inttostr (d1)+inttostr( d2); digitado:=num[ 10]+num[11] ; If calculado=digitado then CPF:=True Else CPF:=False; end Else CPF:=False; end; e para CNPJ function TForm_PRINCIPAL. CGC(num: string): boolean; var n1,n2,n3,n4, n5,n6,n7, n8,n9,n10, n11,n12: integer; d1,d2: integer; digitado, calculado: string; Confere:boolean; begin Confere:=True; Try n1:=StrToInt( num[1]) Except Confere:=False end; Try n2:=StrToInt( num[2]) Except Confere:=False end; Try n3:=StrToInt( num[3]) Except Confere:=False end; Try n4:=StrToInt( num[4]) Except Confere:=False end; Try n5:=StrToInt( num[5]) Except Confere:=False end; Try n6:=StrToInt( num[6]) Except Confere:=False end; Try n7:=StrToInt( num[7]) Except Confere:=False end; Try n8:=StrToInt( num[8]) Except Confere:=False end; Try n9:=StrToInt( num[9]) Except Confere:=False end; Try n10:=StrToInt( num[10]) Except Confere:=False end; Try n11:=StrToInt( num[11]) Except Confere:=False end; Try n12:=StrToInt( num[12]) Except Confere:=False end; If Confere=True then begin d1:=n12*2+n11* 3+n10*4+n9* 5+n8*6+n7* 7+n6*8+n5* 9+n4*2+n3* 3+n2*4+n1* 5; d1:=11-(d1 mod 11); if d1>=10 then d1:=0; d2:=d1*2+n12* 3+n11*4+n10* 5+n9*6+n8* 7+n7*8+n6* 9+n5*2+n4* 3+n3*4+n2* 5+n1*6; d2:=11-(d2 mod 11); if d2>=10 then d2:=0; calculado:=inttostr (d1)+inttostr( d2); digitado:=num[ 13]+num[14] ; If calculado=digitado then CGC:=true Else CGC:=false; end Else CGC:=False; end; ____________ _________ _________ _________ _________ _______ Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora! http://br.mobile. yahoo.com/ mailalertas/ <!-- #ygrp-mlmsg {font-size:13px;font-family:arial,helvetica,clean,sans-serif;} #ygrp-mlmsg table {font-size:inherit;font:100%;} #ygrp-mlmsg select, input, textarea {font:99% arial,helvetica,clean,sans-serif;} #ygrp-mlmsg pre, code {font:115% monospace;} #ygrp-mlmsg * {line-height:1.22em;} #ygrp-text{ font-family:Georgia; } #ygrp-text p{ margin:0 0 1em 0; } #ygrp-tpmsgs{ font-family:Arial; clear:both; } #ygrp-vitnav{ padding-top:10px; font-family:Verdana; font-size:77%; margin:0; } #ygrp-vitnav a{ padding:0 1px; } #ygrp-actbar{ clear:both; margin:25px 0; white-space:nowrap; color:#666; text-align:right; } #ygrp-actbar .left{ float:left; white-space:nowrap; } .bld{font-weight:bold;} #ygrp-grft{ font-family:Verdana; font-size:77%; padding:15px 0; } #ygrp-ft{ font-family:verdana; font-size:77%; border-top:1px solid #666; padding:5px 0; } #ygrp-mlmsg #logo{ padding-bottom:10px; } #ygrp-vital{ background-color:#e0ecee; margin-bottom:20px; padding:2px 0 8px 8px; } #ygrp-vital #vithd{ font-size:77%; font-family:Verdana; font-weight:bold; color:#333; text-transform:uppercase; } #ygrp-vital ul{ padding:0; margin:2px 0; } #ygrp-vital ul li{ list-style-type:none; clear:both; border:1px solid #e0ecee; } #ygrp-vital ul li .ct{ font-weight:bold; color:#ff7900; float:right; width:2em; text-align:right; padding-right:.5em; } #ygrp-vital ul li .cat{ font-weight:bold; } #ygrp-vital a { text-decoration:none; } #ygrp-vital a:hover{ text-decoration:underline; } #ygrp-sponsor #hd{ color:#999; font-size:77%; } #ygrp-sponsor #ov{ padding:6px 13px; background-color:#e0ecee; margin-bottom:20px; } #ygrp-sponsor #ov ul{ padding:0 0 0 8px; margin:0; } #ygrp-sponsor #ov li{ list-style-type:square; padding:6px 0; font-size:77%; } #ygrp-sponsor #ov li a{ text-decoration:none; font-size:130%; } #ygrp-sponsor #nc { background-color:#eee; margin-bottom:20px; padding:0 8px; } #ygrp-sponsor .ad{ padding:8px 0; } #ygrp-sponsor .ad #hd1{ font-family:Arial; font-weight:bold; color:#628c2a; font-size:100%; line-height:122%; } #ygrp-sponsor .ad a{ text-decoration:none; } #ygrp-sponsor .ad a:hover{ text-decoration:underline; } #ygrp-sponsor .ad p{ margin:0; } o {font-size:0;} .MsoNormal { margin:0 0 0 0; } #ygrp-text tt{ font-size:120%; } blockquote{margin:0 0 0 4px;} .replbq {margin:4;} --> _______________________________________________________ Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora! http://br.mobile.yahoo.com/mailalertas/ [As partes desta mensagem que não continham texto foram removidas]