8/29/2025 5:37:16 PM
|
|
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!
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.
|
|
|
|
Format String to Phone Number
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 |
|
|
| |
|
Re: Format String to Phone Number
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.
|
|
|
|
Re: Format String to Phone Number
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. |
|
|
|
Re: Format String to Phone Number
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!!  |
|
|
|
Re: Format String to Phone Number
Posted: 09 Oct 09 7:20 AM
|
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)? |
|
|
|
Re: Format String to Phone Number
Posted: 09 Oct 09 9:42 AM
|
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.
|
|
|
|
Re: Format String to Phone Number
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. |
|
|
|
Re: Format String to Phone Number
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. |
|
|
|
Re: Format String to Phone Number
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 |
|
|
|
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!
|
|
|
|
|
|
|
|