How to handle international + symbol in dialplan?


My mobile phone also works fine as a SIP phone. In my phone’s address book, most number are stored in the international format, eg. +441905xxxxxx . When I select such a number, the phone will dial it through my FreePBX in the same format…

I can handle these numbers and assign outbound routes, however I need to modify the dialling format at the trunk settings. However, the “+” symbol is used there for some other purpose. How can I rewrite an initial + symbol into “00” ? Or simply just strip the “+” from the front?



I know that the use of the + sign to add digits has caused problems for others in route and trunk dial plans… there ought to be a way to represent a literal + sign, maybe + or p or ~ or whatever - just something that would represent a literal plus sign if found in a route or trunk dial rule.

That said, I’m assuming your phone is configured as a SIP extension, so the trick would be to change the context (on the extension’s configuration page) from from-internal to some new context you’ve placed in extensions_custom.conf, then in that context strip the first character (assuming it’s always a +, otherwise you could test to see what it is before stripping) and then send the call on to from-internal.

As an UNTESTED example:

exten => _.,1,Noop(Stripping first character which should always be +)
exten => _.,n,Set(OUTNUM=${OUTNUM:1})
exten => _.,n,Goto(from-internal,${OUTNUM},1)
exten => h,1,Hangup()

Then, in the extension setup you would change the context from from-internal to custom-strip-plus-char

Or, if you need to test for a + sign, this MAY work:

exten => _.,1,Noop(Testing for leading + and stripping if found)
exten => _.,n,GotoIf($["${OUTNUM:0:1}" != "+"]?noplus)
exten => _.,n,Set(OUTNUM=${OUTNUM:1})
exten => _.,n(noplus),Goto(from-internal,${OUTNUM},1)
exten => h,1,Hangup()

Again, all of this is untested, and I’m not even 100% positive that OUTNUM is the correct variable here (if not, try EXTEN), but you can try it and see if it works (please let us know!).

EDIT: I just reread your question and realized I didn’t address the part about adding the “00” - of course you can do that at the route or trunk level, but if you want to do it here it’s easy enough - just change the line

exten => _.,n,Set(OUTNUM=${OUTNUM:1})


exten => _.,n,Set(OUTNUM=00${OUTNUM:1})

Thank you, I will give it a try and report back. In the meanwhile I posted a ticket/request for a patch to allow the matchng of a literal “+”. I believe it is a problem that many have to face.

In our scenario, there are several people with multiple devices connecting the FreePBX, and we need to get this sorted for all extensions and in the easiest possible way.