string format phone number

lawrence whittemore asked on March 10, 2022 16:53

I am using this in an xml transformation and just recently noticed it doesn't work with high numbers that start with like 877.

{% FormatString("{0: (###) ###-####}",Primary.ToInt()) #%}

Any thoughts on what I can do to get those to work?

I've also noticed that if I type in the number manually, it doesn't work when the number is too big

{% FormatString("{0: (###) ###-####}",8779999999); #%}

returns this "(19) 006-5407"

Recent Answers


lawrence whittemore answered on March 10, 2022 22:11

This is what I ended up doing.

x = "(" + Phone.SubString(0, 3) + ") " +  Phone.SubString(3, 3) + "-" + Phone.SubString(6, 4); return x;
0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on March 11, 2022 05:45

Hi Lawrence,

Looking at your code, converting phone number to integer looks really strange. Typical phone number is obviously bigger than int can accommodate, therefore you get this weird behaviour.

Your second solution looks a bit better. However instead of formatting this on the backend I'd recommend doing it via JS when you display these numbers, please refer to this article for example.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.