[asterisk-users] How strip +1 from caller id on inbound call

Anselm Martin Hoffmeister anselm at hoffmeister-online.de
Tue Aug 14 01:47:07 CDT 2007


Am Sonntag, den 12.08.2007, 21:16 -0400 schrieb C F:
> you can do like this:
> exten => _X.,1,GoSubIf($[${LEN(${CALLERID(num)})}>10]?strip1);if it's
> longer than grab the last 10 digits of the CIDNUM
> exten => _X.,50(strip1),Set(CALLERID(num)=${CALLERID(num):$[${LEN(${CALLERID(num)})}-10]});this
> grabs the last 10 digits of CALLERID(num) and sets it to CALLERID(num)
> exten => _X.,n,Return()

Argh! You do not ever get international calls, do you? (Well, Canada
does not count here for obvious reasons)

The clean solution to the question

I get some calls with a leading "+1". If that is the case, how do I
strip that off?

is of course

If the CALLERID(num) starts "+1", re-set it to the same value, offset 2:

...
exten => _X.,n,GoSubIf($["${CALLERID(num):0:2}" = "+1"]?strip1)
...

exten => _X.,n(strip1),Set(CALLERID(num)=${CALLERID(num):2})
exten => _X.,n,Return()

Which leaves international calls for themselves. Of course you still
could replace the leading "+" for all other numbers by "011", if you
like.

Your code would probably handle
+12125551212
correctly, would work OK with
+495924236
(which might or might not be one of the old, short numbers still present
in some places in Germany), leaving it intact, but not with
+4916177554224
which would be remapped to a Boston MA number (actually a Cingular cell
phone number) instead of mapping it to a german mobile phone.

Variable handling (offset et al) is documented on
http://www.voip-info.org/wiki/view/Asterisk+variables

BR
Anselm




More information about the asterisk-users mailing list