Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, August 29, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Format String to Phone Number
Adam Perry
Posts: 5
 
Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Oct 09 11:27 AM
I need to return the value of an object (TEdit for example) as a formatted phone number (i.e. "(401) 555-1111"). The format type on the object is set to ftphone and the value displays fine in the object, but when I refer to the value (TEdit1.Text), it returns the unformatted number (i.e. "4015551111"). Is there a function to format the string or an object property that will return the formatted value?

Thanks,
Adam
[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Oct 09 4:06 PM
Use a regular expression. Google: "RegExp Phone Number"

http://regexlib.com/DisplayPatterns.aspx?cattabindex=6&categoryId=7
[Reply][Quote]
Adam Perry
Posts: 5
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Oct 09 5:24 PM
Is there an easier way? I'm trying to do this with a regexp replace, but the back references are going to be different depending on how the number was entered. I'm probably not doing it right. I've never been good with regular expressions. This is the pattern I'm using:
^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$

I just want to return the number in a (xxx) xxx-xxxx format. This is what my code looks like:

Set objRegExp = New RegExp
objRegExp.Pattern = "^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$"
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Replace(TEdit.Text, "($3) $4-$5")

Only like I said, I don't know how to use the back references in this case because there will be multiple sub-matches depending on how the number was entered. Is the problem with the pattern or how I'm doing the replace?

I was really hoping there was a way to return the nicely formatted content of the TEdit box.
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Oct 09 5:49 PM
SalesLogix does a bit more than just use a RegEx to format the phone number:

- It removes any extra characters.
- It figures out if there is an extension (looks for "ext" or "x" I believe) [It puts the extension aside, formats the number and then readds the extension]
- It converts any letters to numbers (so if you write down 1800flowers, it will convert the letters to the correct numbesr based on the Phone Number pad - also, it will save the numbers, not the letters, so this conversion is only done upon input)
- It checks the length of the number (And maybe even the locale) and decides how to format it

So if you really want to get the format as SLX does it, you should do a bit more work than just using regex.
[Reply][Quote]
Andrew Grandin
Posts: 272
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Oct 09 5:50 AM
This is just me thinking out loud but, assuming the number will always be in the 4015551111 format, cant you have a second invisible edit box and say:

Edit2.Text = "( + 'first 3 characters of TEdit1.Text' + ) + " " + 'next 3 characters of TEdit.Text' +"-"+ 'final 4 charcters of TEdit1.Text'"

P.S i know the code isnt exactly right there

and then refer to the value in this box as the formatted telephone number.

I have done something exactly like this is an earlier customisation, i can dig the code out if you want but if i can do it anyone can!!
[Reply][Quote]
Trent Haynes
Posts: 32
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Oct 09 7:20 AM
Quote:
Originally posted by Raul A. Chavez

SalesLogix does a bit more than just use a RegEx to format the phone number:

- It removes any extra characters.
- It figures out if there is an extension (looks for "ext" or "x" I believe) [It puts the extension aside, formats the number and then readds the extension]
- It converts any letters to numbers (so if you write down 1800flowers, it will convert the letters to the correct numbesr based on the Phone Number pad - also, it will save the numbers, not the letters, so this conversion is only done upon input)
- It checks the length of the number (And maybe even the locale) and decides how to format it

So if you really want to get the format as SLX does it, you should do a bit more work than just using regex.


Where does SLX do this? When you use the phone format on an edit control?

I ask because the display/storing of phone numbers is a constant pain in my backside. Does it only do this for US phone numbers (we deal quite a bit in international numbers)?
[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Oct 09 9:42 AM
Quote:
Originally posted by Raul A. Chavez

SalesLogix does a bit more than just use a RegEx to format the phone number:

- It removes any extra characters.
- It figures out if there is an extension (looks for "ext" or "x" I believe) [It puts the extension aside, formats the number and then readds the extension]
- It converts any letters to numbers (so if you write down 1800flowers, it will convert the letters to the correct numbesr based on the Phone Number pad - also, it will save the numbers, not the letters, so this conversion is only done upon input)
- It checks the length of the number (And maybe even the locale) and decides how to format it

So if you really want to get the format as SLX does it, you should do a bit more work than just using regex.


Extensions it looks for an 'x' (not an X).

1800FLOWERS it does keep the characters, it simply formats it correctly.

The basic thing is to store the RAW text, and let SLX or other functions format international or domestic phone numbers.

so right before you use REGEXP you can do stuff like TRIM(), REPLACE, LEFT (,10) etc.
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Oct 09 10:17 AM
Glad to know regarding the Characters, my bad.
I also wanted to point out that you don't want to do a blanket LEFT(, 10).
If the numbers are international, then you are keeping the country code and dropping some of the Important part of the number.
If it is a US number, but you entered it with a leading one (such as the 1800FLOWERS example), you will keep the one and loose a more important digit.

Also, as per the Trent's comment, they do a lot of international number formatting.


I guess the bottom line is that there is no way to get the formatted number from the Edit Box, and if you want to match it, RegEx may be a way, but you have to understand all the rules involved:
- Meassure the Number's Length
- Determine if the Number is International
- If a US number, check the length [drop leading 1 if present], and format accordingly: 10 chars 3-3-4 or 7 chars 3-4. Any other length leave unformatted.
- If it is an International number, apply the International Number formatting (if you know the country that the number belongs to: is it a 1, 2 or 3 digit Country Code?), or leave it unformatted.
[Reply][Quote]
Adam Perry
Posts: 5
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Oct 09 11:37 AM
Yeah, this is definitely turned into one of those "way more work than I wanted to do" projects. I'll keep working the regexp and post it if I get something to work reasonably well. Thanks for the help guys.
[Reply][Quote]
Adam Perry
Posts: 5
 
Re: Format String to Phone NumberYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 09 Oct 09 12:12 PM
I actually found a pretty decent non-regexp function some wrote on this site:
http://www.psacake.com/web/func/

I modified it slightly to leave the number alone if it doesn't match. So, it won't format international numbers, but I don't care about that. It could certainly be modified to do that using the same logic.

Function MkPhoneNum(byVal phonenum)
Dim tmp
phonenum = CStr( phonenum )
phonenum = Trim( phonenum )
phonenum = Replace( phonenum, " ", "" )
phonenum = Replace( phonenum, "-", "" )
phonenum = Replace( phonenum, "(", "" )
phonenum = Replace( phonenum, ")", "" )
Select Case Len( phonenum )
Case 7
tmp = tmp & Mid( phonenum, 1, 3 ) & "-"
tmp = tmp & Mid( phonenum, 4, 4 )
Case 10
tmp = tmp & "(" & Mid( phonenum, 1, 3 ) & ") "
tmp = tmp & Mid( phonenum, 4, 3 ) & "-"
tmp = tmp & Mid( phonenum, 7, 4 )
Case 11
tmp = tmp & Mid( phonenum, 1, 1 ) & " "
tmp = tmp & "(" & Mid( phonenum, 2, 3 ) & ") "
tmp = tmp & Mid( phonenum, 5, 3 ) & "-"
tmp = tmp & Mid( phonenum, 8, 4 )
Case Else
MkPhoneNum = phonenum
Exit Function
End Select
MkPhoneNum = tmp
End Function
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/29/2025 4:42:14 PM