How to format phone numbers

I want to format a phone number ( its sometime coming in the national format and other times in the International format.)

Is it somehow possible to add the country codes when the number comes in the national format and remove the+ in case of international ones? ( the numbers are of a single country)

Can you provide at least five examples per each incoming format, and point out which format you want to convert them to? You also forgot to mention the country code.

e.g.:

123456 => 55123456
+55123456 => 55123456
+32 1234 5678 => 3212345678
654321 => 55654321

2 Likes

@samliew

+88017654566 =>> 017654566

017654566 =>> +88017654566

{{ if(contains(Phone; "+"); replace(Phone; CountryCode; emptystring); CountryCode + Phone) }}

3 Likes

Hi Rezwan,

you can also try the Parse a Phone Number module. You can configure the default country (or map it) and it will provide the number in several different formats, including international (with the country code) and national (without the code) along with a couple of other formats. As a bonus it will also tell you if its a valid number or not.

3 Likes