I’m trying to format a phone number in Architect for a specific outbound campaign. The incoming data is in E.164 format, like +1XXXXXXXXXX. I need to convert it to (XXX) XXX-XXXX for the IVR prompt to sound natural.
I’ve been looking at the expression builder, but I can’t find a direct “format” function that handles this specific pattern. I tried using substring and concatenation, but it’s getting messy with all the parentheses and dashes.
Here’s what I have so far:
"(" + substring(contact.phoneNumber, 3, 3) + ") " + substring(contact.phoneNumber, 6, 3) + "-" + substring(contact.phoneNumber, 9, 4)
This works for US numbers starting with +1. But I’m worried about edge cases. What if the number is +12025551234 (11 digits) vs +442071234567 (13 digits)? The substring indices will break.
I also tried looking for a regex replace function in the expression builder, but it doesn’t seem to support standard regex syntax like ^\+1(\d{3})(\d{3})(\d{4})$.
Is there a better way to do this? I don’t want to write a custom API endpoint just for string formatting if I can avoid it. That seems like overkill for a simple display string.
Also, our team is in Central Time, so we’re dealing with a mix of US and some international clients. I need a solution that’s solid enough to handle the +1 prefix correctly without failing on other country codes.
Any help would be appreciated. I’m stuck on this for now.