Best practice for getting rid of +XX when calling back from a phone

Hi, with standard configuration freePBX sends a CID with +[Countrycode][Number] to the phone. If you want to call back, a number 0[Number] or 00[Number] is required.
Sadly there seems to be no predefined solution.
Some suggest, this can be solved with outbound rules. Although this would be the most logical step, it didn´t work for me.
Others modify extensions_custom.cfg. I don´t know if this is a good idea. Is it resistant against updates and restore? The file seems to be empty on default?
What do you think is best practice for this issue?

Find a provider that is consistent between caller ID and destination number formats. It isn’t Asterisk that is adding the +, it is the provider, and if the provider uses this on caller ID, it should accept it on dialled numbers.

Hi, @david55 this would be a workaround, but not best practice. There should be a solutions to use most (or even any) of the providers with freePBX.

Personally, I use this solution:


exten => _X!,1,GotoIf($[“${CALLERID(num):0:3}” != “+55”]?noplusatstart)
exten => _X!,n,Set(CALLERID(num)=${CALLERID(num):3})
exten => _X!,n(noplusatstart),Goto(from-trunk,${EXTEN},1)

After you create this custom-context, you just need to define it in the trunk configuration

This is a dialplan that removes the “+” and the countrycode from the number (basically removing the first three digits that are always fixed, in my case “+55”), so I receive the callerid in an appropriate format to call back (my outbound rules already add the necessary 0 in front of the number)

Hi, @ErikVandergeld by the way for most cases 3 digits fixed is correct. Country codes however can be 1 or 3 digits too.
Is it correct, with custom-context you referre to the field , default setting is “from-pstn”. The value in this field is used as the header for the script in “extensions_custom.conf”? Has the field entry to be unique or can it be used for all trunks? Has it to be changed at all, if all trunks have to be processed by the script?

Contexts can be shared between endpoints.

You can define this context in the trunks you want to use it, which (sometimes) may depend on the format in which the callerid is sent

For example: I have two trunks on my PBX, one from a large telecom company and the other from a VOIP provider, the telecom company’s trunk sends me the callerid as “+55XXXXXXXXXXX” so I use that context in its configuration:

exten => _X!,1,GotoIf($[“${CALLERID(num):0:3}” != “+55”]?noplusatstart)
exten => _X!,n,Set(CALLERID(num)=${CALLERID(num):3})
exten => _X!,n(noplusatstart),Goto(from-trunk,${EXTEN},1)

Now the VOIP provider sends me this without the “+”, so the context is slightly modified:

exten => _X!,1,GotoIf($[“${CALLERID(num):0:2}” != “55”]?noplusatstart)
exten => _X!,n,Set(CALLERID(num)=${CALLERID(num):2})
exten => _X!,n(noplusatstart),Goto(from-trunk,${EXTEN},1)

See that in the first line, the country code (two digits) is defined and in the next lines we remove the first two digits of the number

So if you want all your trunks to pass this rule, you could set the context for all of them to be “from-pstn-remove-plus” (or whatever name you use in extensions_custom.conf)

Asterisk is distributed with a context in /etc/asterisk/extensions.conf called


I suggest that whatever your country-code is, it might help you study it for how the various possible formats are handled to ‘normalize’ dialing to your own [from-pstn-e164-br] where br is your country-code.

It should be noted that the -us context normalizes to 10 digit dialing, yet more and more locales are needing or at least accepting, 11 digits , so I suggest you bear in mind what is the recognised diling for the users in your locale is , so callers can be called back easily. Outboun\d routes can be handled both generically in the route and more specifically individually in the trunks.

1 Like

First in [admin][config edit] there is “custom_extensions.conf” and “extensions.conf”. The second one should not be edited because it is modified by gui. Is this correct?

Second I have tried Erik´s script in “custom_extension.conf”. I modified it to

exten => _X!,1,GotoIf($[“${CALLERID(num):0:3}” != “+49”]?noplusatstart)
exten => _X!,n,Set(CALLERID(num)=0${CALLERID(num):3})
exten => _X!,n(noplusatstart),Goto(from-trunk,${EXTEN},1)

(+49 for Germany and adding a 0 in front of the number)

Nothing happens. This is o.k… After changing the context in the trunk configuration, the number can not be reached anymore. Like there is no “inbound rule”. The log shows:

to extension ‘+49…’ rejected because extension not found in context ‘from-pstn-remove-plus’.

I have modified the inbound rule from ‘+49…’ to ‘0…’. Same result.
What have I forgotten?

Normalizing sounds good. But first I would be glad, if basic functions for the home country will operate with the favorite trunk…

X does not match + just 0-9.

Hi dicko, can´t exactly comprehend, what you mean with “X” and how to solve it. Could you or somebody give me a hint, where to find a detailed description of the language or what´s the name of the language to search for a description. Thanks.

Here ‘X’ is asterisk dial-plan talk for ‘[0-9]’, ‘Z’ is ‘[1-9]’ and ‘N’ is ‘[2-9]’ finally ‘.’ is for any-single-character including ‘+’

For dial-plans by country I use wikipedia, for an example

Idealy you will cover local , long distance, Euro and International dialing by any idiom found in your locale. also cover emergency and other common ‘short number’ of relevance and everyone will be happier.

Globally, Phone numbers fit within E164 :-
In some countries all phone numbers are the same length (fixed) unfortunately for you, Germany is not one of those so a complete set of unique (there was a truly good historical reason for that but it didn’t work out) MostSignificantNumbers is much longer than the 1NXX (then NXX-XXXX) of NANP, but that’s another story.

E164 also covers mobile/cell phones whereby any James Bond ‘InternationalWhatAGuy’ knows a long press of the 0 will turn into a + which is the intermationally accepted meta character for international call prefix, 011 in NANP 00 in most of the rest of the world, The + is that he can dial M (for murder or mothering) from London, Moscow or Jamaica