Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Phone Number formatting Post Reply Post New Topic
Author Message
stephanie685
Newbie
Newbie


Joined: 30 Nov 2011
Location: United States
Online Status: Offline
Posts: 3
Quote stephanie685 Replybullet Topic: Phone Number formatting
     Posted: 30 Nov 2011 at 5:53am
Hello,
 
I have to pull phone number data from a text field. The phone number field does not have any kind of imput mask and the people entering the data have used all sorts of symbols such as 555/555-5555, 555-555-5555, (555) 555-5555, or 555.555.5555. Also there is text added to some records such as "(555) 555-5555 cell", or "555-555-5555 brother's phone number." I need to pull this data in the format 555-555-5555 with out any of the other symbols or added text. I know ther is a picture() function, is this the way to go? Thank you for any help. 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 30 Nov 2011 at 9:00am
how about something like:
 
local stringvar phone;
local numbervar x;
local stringvar one;
for x = 1 to len({table.field}) step 1(
  one := mid({table.field}, x,1);
  if isnumeric(one) then
    phone := phone + one;
);
 
if len(phone) >= 10 then
  "(" left(phone,3)+ ")" + mid(phone,4,3) + "-" + mid(phone,7, 4)
else
  phone
 
 
ie, string out all the non numerics and format what is the first 10 digits (incase there are extensions)
if the dialing outside the north american dialing area, all bets are off, but for US/Canada this works.
 
HTH
IP IP Logged
stephanie685
Newbie
Newbie


Joined: 30 Nov 2011
Location: United States
Online Status: Offline
Posts: 3
Quote stephanie685 Replybullet Posted: 30 Nov 2011 at 9:40am
I tweeked it a bit and it worked! You need a Do statement after Step 1. Thank you very much for your help! Ireally appreciate it!!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 01 Dec 2011 at 2:21am
np. 
 
I don't use for loops too often, so I tend to forget the syntax.
 
tweek away, as my goal is to assist / provide a path to the solution, not necessarily the answer itself.
IP IP Logged
CircleD
Senior Member
Senior Member
Avatar

Joined: 11 Mar 2011
Location: United States
Online Status: Offline
Posts: 251
Quote CircleD Replybullet Posted: 01 Dec 2011 at 12:56pm
If the field is in a string format this would have worked too:

picture(replace(replace(replace(replace(replace({table.telephonefield},'(',"),')',"),',"),'-',",'cell',"),'(XXX)XXX-XXXX')
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum