Need to remove +<country code> from dial

I need to remove + from dial string f.ex: +46. However, since the + symbol is used to put together strings I am not able to fix it.

The problem is that I use my Nokia N95 as a SIP phone when I’m at home. But when I’m abroad, I need the +46 in front of the phone number when using the phone book.

Any ideas?


In many computer languages, if you want to have a character that normally has a special meaning taken literally, you escape it - often the escape character is a backslash. So if this were true in FreePBX, using just + would put together strings, but using + would take the + as part of the string itself, not as an operator. But, I do not know if that works in FreePBX, but it might be worth trying if you have not done so already.

In my outbound route, i have added it as a dial pattern


Thank you for your advice!

Unfortunately does not Asterisk accept \ in the dial plan. I have also tried to double-+: ++46 |. still no success.

More ideas?

Best regards,
Måns Åman

Example of a phone number in the phone book: +46890510 or +46374123456

When dialed it should be: 0890510 eg. remove: +46 and add: 0

I tried this: +46|0.

What do you think?


The character + is not a valid character for DTMF (search dtmf tones for more info, So it is never realy transmitted over a phone network to begin with. Try doing what you need without the + character at all.

If your phone is transmitting that character then it is a bug in the code in the phone.

See RFC 4733 (at for example), section 3.2 as it lists the supported dtmf tones and the + is not a valid character.

Yes I know not the answer you want but at least some enlightenment on the issue?


Thanks for your replay!

I follow you about DTMF! But how about mobile phones? They have and they use the ±sign…

Also I fount this at

" If the telephone number is a local or national telephone number, IP
Client MUST convert that telephone number to an international
telephone number by adding the appropriate leading digits (e.g.,
area code and/or country code plus the leading “+”) unless IP Server
allows a local or national number in the SIP INVITE messages. "

To me it sounds like SIP supports the ±sign… and I have a SIP-phone connected to Asterisk/FreePBX calling through
a SIP-trunk.

Best regards,
Måns Åman

I see that. But as a draft it has a 6 month life and of nothing is done then it expires.

Take a look at and search for draft-yu-sip-np-02 you will see it expired with no update, revision or adoption

Did anyone ever work out a solution for this ? I read all the above comments and all the messages about DTMF and the draft etc. are completely irrelevant. Any mobile phone that talks SIP and dials a number from the phonebook will send a number starting with a + and the country code to asterisk. At home (where i do not use FreePBX) i have the prefix fixed in this way :

exten = _+31.,1,Goto(0${EXTEN:3},1) ; Change +31 to 0
exten = _+.,1,Goto(00${EXTEN:1},1) ; Change + to 00

I included this before anything else in my dial plan, which brings the number back to a format that the rest of my dialplan understands and proceeds with proper outbound dialling rules.

But how to do this in FreePBX? Is there a custom bit where i could insert such code?

You can put this code into extensions_custom.conf this is where you would define custome code such as this that does not get overwritten when FreePBX rewrites the config files.

I use a very similar piece of code to remove the +1 that is added to beginning of all DIDs and CIDs from calls coming in on a trunk. The code I am using follows:

exten => _+1.,1,Set(DID=${EXTEN:2})
exten => _+1.,n,Set(CALLERID(num)=${CALLERID(num):2})
exten => _+1.,n,Goto(from-trunk,${DID},1)

The first line fixes the DID, the 2nd line fixes the CID then the call is transfered to the from-trunk context. This code removes the +1 as the call is coming in so that I don’t have to deal with a +1 in all of my recent calls used for last call return etc

Thanks for the tip! I tried, but failed and don’t know where i go wrong. I created a SIP extension for my mobile phone and verified it works. Then, in that SIP extension i changed the context to from-mobile-sip

In extensions_custom.conf i created this :
exten => _+31.,1,Goto(0${EXTEN:3},1) ; Change +31 to 0
exten => _+.,n,Goto(00${EXTEN:1},1) ; Change + to 00
exten => _.,n,Goto(from-internal,${EXTEN},1)

When i dial a number my asterisk console shows this :
– Executing [+31206666666@from-mobile-sip:1] Goto(“SIP/201-b760a668”, “0206666666|1”) in new stack
– Goto (from-mobile-sip,0206666666,1)

I am not sure what the |1 after the first Goto SIP means, but i believe the real problem is in the next line, i may have done something wrong on my Goto command ?

I think your Goto in the first two lines is wrong.

Try this:

exten => _+31.,1,Goto(from-internal,0${EXTEN:3},1) ; Change +31 to 0 and goto from-internal exten => _+.,1,Goto(from-internal,00${EXTEN:1},1) ; Change + to 00 and goto from-internal exten => _.,1,Goto(from-internal,${EXTEN},1) ; everything else goto from-internal w/ochange

Since each line has a different pattern, each one starts with a priority 1 rather than n.

Reading the definition of Goto at voip-info I guess you could do a Goto without the context in the first two lines, and it should drop down to the last line, but only if each of them have priority ‘1’. You only go on to subsequent priorities if EXTEN stays the same (or at least is matched by the same pattern).

The way you have written it, because there is no pattern with priority 1 which matches your modified EXTEN (0${EXTEN:3}), the target of the GOTO is undefined but it never ends up on your third line.

Any chance that a fix for this might get included in FreePBX somewhere?

I assume more and more people will be connecting mobile GSM/G3 phones to their Asterisk boxes to take advantage of their unlimited internet plan :slight_smile:

Using mobile phone as a dual phone: mobile and sip (over wifi) connecting to Asterisk box. All entries in the phone book have plus sign “+” in front of the phone number (required to make mobile calls). When making a call using phone book entry using sip, it fails with the message “Address not in use”.

I need to remove “+” from the dial string, however, since the “+” symbol is used to put together strings, I cannot construct correctly the dialing pattern for my trunk or for the outbound route.

This is how we did this. We use 0 the get a outbound line or +46.

Original from FreePBX (extensions_additional.conf):

include => outrt-009-MA_Hemma-custom
exten => _0.,1,Set(MOHCLASS=${IF($[“x${MOHCLASS}”=“x”]?Aman:${MOHCLASS})})
exten => _0.,n,Macro(user-callerid,SKIPTTL,)
exten => _0.,n,Set(_NODEST=)
exten => _0.,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _0.,n,Macro(dialout-trunk,5,${EXTEN:1},)
exten => _0.,n,Macro(outisbusy,)

; This is what we added
exten => _[+]46.,1,Set(MOHCLASS=${IF($[“x${MOHCLASS}”=“x”]?Aman:${MOHCLASS})})
exten => _[+]46.,n,Macro(user-callerid,SKIPTTL,)
exten => _[+]46.,n,Set(_NODEST=)
exten => _[+]46.,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _[+]46.,n,Macro(dialout-trunk,5,${EXTEN},)
exten => _[+]46.,n,Macro(outisbusy,)

This case only handle one country (+46) because the rest will go through another trunk…