Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Phone Numbers

Status
Not open for further replies.

dawtes

Programmer
Jun 23, 2005
31
US
Hello,
Any idea how these records can be formated to
(XXX)-XXX-XXXX.

507/437-4615
320-274-7433
320-685-7700
651-222-5555
218-847-
320-847-2419
6128691900
6128691900
218-759-8859
218-759-8859
218-631-1400
507-754-6107
1-800-258-2585

I would really appreciate it.
 
Try two formulas:

//{@phone}:
if {table.phone} startswith "1-" then
mid({table.phone},3) else {table.phone}

{@displayphone}:
picture(replace(replace({@phone},"-",""),"/",""),"(xxx)-xxx-xxxx")

Although I think the more usual display is: (xxx) xxx-xxxx

-LB
 
After suggesting to the interface coders and the dba that they fall back to their real careers, and buying them their first bottle of MD20/20 to get then started, you'll probably need to use numerous checks for sanity, here I added a check for spaces:

I'd further wrap LB's
stringvar MyPhone:= replace(replace(replace({@phone}," ",""),"-",""),"/","");
// Then do some sanity checking:
if len(trim(MyPhone)) = 10 then
picture(MyPhone,"(xxx)-xxx-xxxx")
else
"*"&picture(MyPhone,"(xxx)-xxx-xxxx")

The second adding an asterisk to identify bad numbers.

There are plenty of other checks done to bad phone numbers, but the point is to correct the front end, adn issue a update/replace against the database to fix the problem permanently.

-k
 
Great, if you still have difficulties, this will strip everything out except numeric values (probably the better solution overall):

whileprintingrecords;
numbervar Counter;
Stringvar MyPhone:="";
For Counter := 1 to len(trim({Customer.Phone})) do(
if isnumeric(mid({Customer.Phone},counter,1)) then
MyPhone:=MyPhone +mid({Customer.Phone},counter,1)
);
MyPhone

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top