Telephone number formatting

290 views
Skip to first unread message

John DeGrace

unread,
Jan 28, 2020, 3:31:46 PM1/28/20
to XMPie Interest Group
Hello,
I am new to XMPie and simply want to ensure that while entering a Variable Phone number, the dots remain as a separator (example: 123.456.7890) Is there a simple recipe for this? Thank you in advance.
John

Sylvain

unread,
Jan 28, 2020, 3:49:52 PM1/28/20
to XMPie Interest Group
How are you getting the phone number?
If you are getting it from uStore, you could enforce a regular expression on the phone number field.
Otherwise, in the plan, you could put the phone number through a JavaScript function to extract only the numbers, then use the QLingo FormatNumber function.

FormatNumber(JSFunction(NumberField), "###.###.####")

eko...@gmail.com

unread,
Jan 28, 2020, 10:08:59 PM1/28/20
to XMPie Interest Group
Hi John and welcome to XMPie,

Based on your question, I assume you are talking about uStore.

The simplest way to accomplish the task is to use the settings at the bottom of the Customization Dial screen. See screenshot for a visual reference.
  • Use the Drop Down for US Phone Format to populate the Regular Expression text box. Then edit the expression as needed.
  • Don't forget to add the error message to help the user when he/she does not follow the pattern.

There are far more interesting ways to solve this puzzle by forcing the formatting as the user types. 
  • There is plenty javascript code out on the internet to guide/force the user to provide a variety of phone number formats (domestic/international/etc). 
  • You'd use the Input Control named "HTML Generic" to accomplish the more robust user interface.
USPhoneFormatOnInput.JPG

John DeGrace

unread,
Jan 28, 2020, 11:43:26 PM1/28/20
to XMPie Interest Group
Hello,
Thank you. I am going through uCreate through InDesign. I have a csv file set with Phone1 and 123.456.7890. I don't know JavaScript, and wonder if there is a way to do it through the InDesign interface? Do you place an expression in the Phone1 Content Object rule? If so, what is the order of the rule? i.e - Value= FormatNumber...then what? Thanks-John

eko...@gmail.com

unread,
Jan 29, 2020, 12:27:48 AM1/29/20
to XMPie Interest Group
If the dots are in your csv data, then you are good to go.

If you have mixed formats with (), dashes, spaces, etc, then you might need to remove all of that and then apply the periods in the right positions. Essentially, clean the value into 10 digits, and then take the first 3 digits, add a period, three more digits, then another period, and the final 4 digits.

The cleanest way to do this is to add a Variable in InDesign with a bunch of FindAndReplace() nested together to clean it up: (If you have other extra characters in the data, then you need to strip that out as well. Extensions will not work with this approach, nor country codes)
FindAndReplace(FindAndReplace(FindAndReplace(FindAndReplace(FindAndReplace(|->[Phone], "(", ""), ")", ""), "-", ""), ".", ""), " ", "")
Then we bring this into the ADOR: 
SubString(@{PhoneJustDigits}, 0, 3) & "." & SubString(@{PhoneJustDigits}, 3, 3) & "." & SubString(@{PhoneJustDigits}, 6, 4)

I've attached a sample InDesign file and a simple csv.
PhoneFormatting.indd
sampledata.csv

Sylvain

unread,
Jan 29, 2020, 9:48:34 AM1/29/20
to XMPie Interest Group
If you're in inDesign only, then you could create a QLingo Extension to take care of that for you. QLingo extensions are quick, easy, and fun to setup.
Reply all
Reply to author
Forward
0 new messages