Skip to main content
Best answer

How to replace the beginning of phone numbers in different formats

  • July 23, 2026
  • 5 replies
  • 46 views

Forum|alt.badge.img

Hi,

I need to replace the beginning of phone numbers, but can’t figure out how to do it.

The case is such that I get phone numbers as input that are in two different formats, one international (+358….) and one local (040….). I need to transform the local ones to international format, i.e. replace the first zero with +358.

Using the Formatter/Replace function and then Find=0 and Replace=+358 of course replace all zeroes. The Formatter/Find function would find only the first occurrence, but in Replace there is no such parameter.

Any suggestions how to achieve this?

Cheers,

Björn

Best answer by aiappsapi

Two options before reaching for a full Code step.

Formatter > Numbers > Format Phone Number is built for this case. Set the country to FI and the output format to E164, and a local 040 number comes back as +358..., while a number already in +358 form passes through unchanged. That handles both of your input formats in one step with no matching logic.

If you would rather keep it explicit, split the two cases with Paths, one for numbers starting with + (pass through untouched) and one for numbers starting with 0. On the zero path, Code by Zapier is cleaner than any Replace trick:

output = [{phone: inputData.phone.startsWith('0') ? '+358' + inputData.phone.slice(1) : inputData.phone}];

One thing worth doing first either way: strip spaces and dashes with Formatter > Text > Replace, otherwise 040 123 4567 and 040-1234567 behave differently downstream and you end up debugging the wrong step.

5 replies

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • July 23, 2026

Hi ​@BjörnE 

Try one of these options:


Forum|alt.badge.img+1
  • New
  • Answer
  • July 25, 2026

Two options before reaching for a full Code step.

Formatter > Numbers > Format Phone Number is built for this case. Set the country to FI and the output format to E164, and a local 040 number comes back as +358..., while a number already in +358 form passes through unchanged. That handles both of your input formats in one step with no matching logic.

If you would rather keep it explicit, split the two cases with Paths, one for numbers starting with + (pass through untouched) and one for numbers starting with 0. On the zero path, Code by Zapier is cleaner than any Replace trick:

output = [{phone: inputData.phone.startsWith('0') ? '+358' + inputData.phone.slice(1) : inputData.phone}];

One thing worth doing first either way: strip spaces and dashes with Formatter > Text > Replace, otherwise 040 123 4567 and 040-1234567 behave differently downstream and you end up debugging the wrong step.


Forum|alt.badge.img
  • Author
  • Beginner
  • July 27, 2026

Thank you ​@Troy Tessalone!

I had not used AI steps before, but I implemented that now, and it works beautifully. Good to learn. However, the later reply employing Formatter/Numbers/Phone Number → E164 is better, since it does away with using two different paths later on. I of course had already implemented the AI step when seeing that, but so it goes :).

Rgds,

Björn


Forum|alt.badge.img
  • Author
  • Beginner
  • July 27, 2026

Thank you ​@aiappsapi!

I had already implemented an AI step which then required Paths when I saw your reply, but this approach is much cleaner. I tested this and will insert the E164 conversion to make the 040-path unnecessary.

Rgds,

Björn

PS. In my case I always get correctly formatted number strings, but it was to point out the need for stripping dashes and spaces.


SamB
Community Manager
Forum|alt.badge.img+11
  • Community Manager
  • July 27, 2026

So glad you got this sorted ​@BjörnE! 🎉 Big thank you to ​@Troy Tessalone and ​@aiappsapi for jumping in to help out here! 🤗