Phone number format Extract 10 digit number without area code and dash

I just want to format phone numbers without area code and dashes just the extract the 10 digits number.

For example when I extracted this phone number +1 336-207-0212 and added it into the google sheet it becomes an error. I figured it out added =”Phonenumber”, but for my next automation the phone number needs to be 3362070212. Is there any way to extract the 10 digits number even if the area code is different it might be +1 next it is +63.

Can someone help me thank you

Hi @franz21,

I’m sure there are great APIs out there to format phone numbers in various ways.
Nowadays for a task like this I’d use an AI Model. You can use the Make AI Content Extractor or Gemini’s ‘Extract Structured Data’ module to do so or any other AI Model provider :slight_smile:

If you try a few prompts you’ll find one that converts the number reliably.

Happy to see other approaches to this! :slight_smile:

Best,
Richard

1 Like

Hi @franz21,

Welcome to the community. I had a look at your problem, and will provide the screenshots of the solution below.

This is the scenario I used to test:

In the Set Variable module, I set up a phone number. On one hand I tried your phone number with +1, and on the other hand +63, they both work with this formula:

And the output (as proof) in the Excel sheet:

However, I did some research, and area codes can (in some countries), take multiple digits. So this will not work for an area code of 3 digits or more. I already have an idea on how to fix that, but for now you can use this if your area codes only have 1 or 2 digits. For the general solution I will assume that **all your phone numbers have a space between the area code and the 10 digit number you want to retrieve, right?**

Hope this helps, I will be back with you with the general solution

2 Likes

Hi,

The general solution was a lot easier to construct than I thought, there you go:

Remember, this assumes a space to always occur between the area code and the 10 digit number, and the phone number to exist. If this is not the case, the formula won’t work for the cases that do not match my assumptions.

If there are other formats possible, there are still solutions possible, I just need to know every possible format that the phone numbers can be in.

This is the code copied right from my Make scenario:
{{replace(substring(1.Phone number; indexOf(1.Phone number; space); length(1.Phone number)); “-”; emptystring)}}

1 Like

Forgot to provide proof that it did work:

2 Likes

Hi @franz21

For a simpler approach, I would go with AI, as @R-SimplifiedWebhooks suggested.

However, that’s another API to use and, since your use case is pretty simple, you can just use Make’s built-in modules.

Add a text parser with the pattern \d+ and Global match set to Yes.

It will return every group of digits as a bundle.

Add a Text Aggregator and you’ll have the whole number as a string:

From this point on, you have two options:

  1. If you know the length of the phone number, just use the {{substring({{number}};<start>;<end>)}} function when inserting the value with the Google Sheets app. However, this does not work for all international numbers, as lengths vary. In North America you have the 3-3-4 pattern. In Brazil, for example, it can be 2-5-4 OR 2-4-4.
  2. If this should match any international phone number, you may add another step to retrieve only the international prefix and then remove it from the string. Add another Text parser with the pattern ^+(\d+)(?=\D) and it will give you the number(s) after + and before any non-digit character (space, parenthesis, dash etc). OR, use Bundle 1 from the previous match, if you are sure the number always contains an international prefix. Then, subtract its length from the whole string and you’ll have your number.

@damato

2 Likes

thank you so much man!

1 Like