Subject Re: [firebird-support] Best way to store Phone Numbers ??
Author Woody (TMW)
From: "Rich Pinder" <rpinder@...>
> Thanks Daniel and Lucas for replies.
>
> Should have mentioned - I'm located in that big country with gas
> guzzling cars (Los Angeles, to be exact).
>
> My needs are much simpler here than the complex number issues you have -
> and I'm not allowing for non-US numbers.
>
> So all I'm wanting to do is turn:
>
> 8185223329
>
> into:
>
> (818) 522-3329
>
> (which was why I said simple picture masks for languages like Delphi
> take care of lots of headaches for user entry).

I use a fairly simple routine that I wrote some time ago to format phone
numbers. You could probably turn it into an UDF easily enough if you'd like
to use it as a starting point.

Woody (TMW)

function FormatPhone(s: string): string;

function GetPhoneNumberStr(s: string): string;
{ strips out all non-numeric characters first }
var
x: integer;
s1: string;

begin
s := Trim(s);
if s = '' then
begin
result := '';
exit;
end;
try
s1 := '';
for x := 1 to length(s) do
if s[x] in ['0'..'9'] then
s1 := s1 + s[x];
result := s1;
except
result := '';
end;
end;

begin
try
s := GetPhoneNumberStr(s);
if Length(s) > 7 then
result := '(' + copy(s,1,3) + ') ' + copy(s,4,3) + '-' +
copy(s,7,4)
else if (s = '0') or (s = '') then
result := ''
else
result := '( ) ' + copy(s,1,3) + '-' + copy(s,4,4);
except
result := '';
end;
end;