[Delphi Tip] 전화번호에 하이픈(-) 삽입

반응형

 

델파이 팁 : 전화번호에 하이프("-") 넣는법

전화번호에 "-"(하이픈) 넣는 방법 입니다.

 

 

 소스

uses에 MaskUtils 선언 합니다.



function  SetTelephone(vStr :String):String;        //전화번호에 하이픈넣기
var vTemp :String;
begin
  vTemp := CtoC(vStr,'-','');

  case Length(vTemp) of
     7 : Result := FormatMaskText('!000-0000;0; ',vTemp);
     8 : Result := FormatMaskText('!0000-0000;0; ',vTemp);
     9 : Result := FormatMaskText('!00-000-0000;0; ',vTemp);
    10 :
       begin
         if Copy(vTemp,1,2) = '02' then
            Result := FormatMaskText('!00-0000-0000;0; ',vTemp)
         else
            Result := FormatMaskText('!000-000-0000;0; ',vTemp);
       end;
    11 : Result := FormatMaskText('!000-0000-0000;0; ',vTemp);
    else Result := vStr;
  end;
end;

function CtoC(S:String; Oldch, NewCh :String) :String;
begin
  Result := StringReplace(S,Oldch,NewCh,[rfReplaceAll]);
end;

 

 구현

 


edt_Tel.Text := SetTelephone(edt_telNo.Text);// 일력문자(021234567)

 

 결과

 

마무리

함수로 간단하게 처리 할 수 있는  기능 입니다.

 

 

반응형

이 글을 공유하기

댓글