Hello,
I am trying to use the Formatter step to format phone numbers by splitting the country code from the rest of the number.
I tried to do it using the split text. I need help in knowing what to put in the Separator field.
Thanks,
Hello,
I am trying to use the Formatter step to format phone numbers by splitting the country code from the rest of the number.
I tried to do it using the split text. I need help in knowing what to put in the Separator field.
Thanks,
Hi
It sounds like you are trying to do this with a Text Formatter step.
I would recommend using a Number Formatter step (phone formatter) where you can choose an output that doesn’t have the country code.
Here is a picture of what I mean. Hope this helps!
thanks for the above tip.
That works if I wanted to remove the country code.
However, what I want to do is split the country code and send to a destination field and send the rest of the number to another destination field.
Example:
Input: +97300000000
Desired output:
Item1: 973
Item2: 00000000
Appreciate support here.
Thanks,
Hi Rawan,
In that case, here is a Code by Zapier action that I believe would work for you.
Just make sure that you map the field where you see +5550123456789 so that it will be dynamic.
I’ll also put the code below so you can copy/paste.
let phoneNumber = inputData.number;
phoneNumber = phoneNumber.replace(/\D/g, "");
let countryCode = phoneNumber.slice(0,-10);
let tenDigitNumber = phoneNumber.slice(-10, phoneNumber.length);
output = u{countryCode, tenDigitNumber}];
Thanks for the above. That helps.
Would this work with 8 digit numbers ? I see the following note under the phone field in my Action:
“Must be at least a 10- or 11-digit number. This field has a limit of 40 characters.”
The destination has a limit of 8 numbers.
Thanks,
Hi
As far as the code is concerned, you can just change the “-10” in the code to be “-8” in each spot.
Your main issue seems to be that the application you are sending the number to only accepts 10 or 11 digits numbers (likely assuming North American numbers).
I would suggest looking in the settings of your app to see if you can change the phone format to 8 digits.
Hope that helps!
If you want to always remove the first three characters you can change the slice call to slice(3)
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.