Buscar

Formatar cpf/cnpj

Código

Essa função formata Cpf/Cnpj sem q o usuario tenha q digitar os pontos, traços e barra

function TfrmFuncoesProcedures.FazDoc(fDoc: String): String;
Var vTam, xx : Integer;
    vDoc : String;
begin
vTam := Length(fDoc);
For xx := 1 To vTam Do
   If (Copy(fDoc,xx,1) <> '.') And (Copy(fDoc,xx,1) <> '-') And (Copy(fDoc,xx,1) <> '/') Then
      vDoc := vDoc + Copy(fDoc,xx,1);
fDoc := vDoc;
vTam := Length(fDoc);
vDoc := '';
vDoc := '';
For xx := 1 To vTam Do
   begin
   vDoc := vDoc + Copy(fDoc,xx,1);
   If vTam = 11 Then
      begin
      If (xx in [3,6]) Then vDoc := vDoc + '.';
      If xx = 9 Then vDoc := vDoc + '-';
      end;
   If vTam = 14 Then
      begin
      If (xx in [2,5]) Then vDoc := vDoc + '.';
      If xx = 8 Then vDoc := vDoc + '/';
      If xx = 12 Then vDoc := vDoc + '-';
      end;
   end;
Result := vDoc;
end;

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Object pascal
Adicionada dia: 31/10/07
Por: Ricardo
Visualizada: 12174 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009