Fórum Mascara de Telefone #189081
16/10/2003
0
PRECISO DE UMA MASCARA PARA FORMATAR TELEFONES COM 7 e 8 DIGITOS JUNTO AO DDD DA CIDADE, EXEMPLO:
(XX) XXX-XXXX
ou
(XX) XXXX-XXXX
EXATAMENTE ASSIM, COM O HIFEN NO NUMERO E COM OS PARENTESES NO DDD. VALE A PENA RESSALTAR QUE AO DIGITAR DESTA FORMA: 121231234 ELE FIQUE ASSIM:
(12) 123-1234
SE CASO FOR 8 DIGITOS: (12) 1234-1234
OBRIGADO E AGRADEÇO MUUUUUUUITO!!!
NELSON
[i:c2f0f7caa9]Título em maiúsculas editado. Digite suas mensagens em minúsculas. Leia as [url=http://delphiforum.icft.com.br/forum/viewtopic.php?t=6689&sid=add834b4ed94967502cf2381c38e751a][u:c2f0f7caa9]Regras de Conduta[/u:c2f0f7caa9][/url]. (marcelo.c – Moderador)[/i:c2f0f7caa9]
Njunior
Curtir tópico
+ 0Posts
16/10/2003
Dbezerra
´(00)0009-0000´
Gostei + 0
18/11/2003
Carlos Bernardo
Crie as funções:
function FormataFone7(const Fone7: string): string;
var
I: integer;
begin
Result := ´´;
for I :=1 to length(Fone7) do
if Fone7[I] in [´0´..´9´] then
Result := Result + Fone7[I];
Result := ´(´+
Copy(Result, 1,2) + ´)´ +
Copy(Result, 3, 3) + ´-´+
Copy(Result,6,4);
end;
function FormataFone8(const Fone8: string): string;
var
I: integer;
begin
Result := ´´;
for I :=1 to length(Fone8) do
if Fone8[I] in [´0´..´9´] then
Result := Result + Fone8[I];
Result := ´(´+
Copy(Result, 1, 2) + ´)´ +
Copy(Result, 3, 4) + ´-´+
Copy(Result,7,4);
end;
valide o componente para receber apenas números
no evento onkeypress do componente digite:
if not (Key in [´0´..´9´,#8]) then
begin
key := #0;
MessageBeep($FFFF);
end;
depois crie condições no onexit no componente
If edit1.text <> ´´ then
begin
If (Length(Edit1.Text) <> 9) and (Length(edit1.Text) <> 10 )then
begin
MessageBox(´Número de telefone inválido.´);
edit1.setfocus;
edit1.Text := ´´ ;
end
else
If Length (edit1.Text) = 10 then
edit1.Text := FormataFone8(Edit1.Text)
else
Edit1.Text := FormataFone7(Edit1.Text);
end;
Espero ter colaborado.......
Gostei + 0
18/11/2003
Jack Stone
!\(99\)_#000-0000;0;_
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)