[Asterisk-Users] Removing "-" (Dash) from Dialed Numbers

Andreas Sikkema andreas.sikkema at bbned.nl
Tue Sep 27 00:25:20 MST 2005


asterisk-users-bounces at lists.digium.com wrote:

>>     I am trying to enable dial-by-email by using LDAPget to query
>>     an Active Directory server.  I've got it retrieving the phone
>>     number fine.  Unforunately, the numbers stored in active
>>     directory are either in the format:  (xxx) xxx-xxxx or
>> xxx-xxx-xxxx. 
>  Is there
>>     any way to parse characters out of the dialed phone number so
>>     that I only end up with digits (remove spaces, parenthesis and
>>      dashes)? From there, my outbound routes can take care of
>>     where to send the call.
> This would be darned easy to do with the AGI and a perl script.
> 
> IE:
> 
> exten => _X.,1,agi,fixnumbers|${MyNumber}
> exten => _X.,2,Dial(ZAP/g0/1${MyNumber})
> 
> Then, in a perl script called "fixnumbers" and inside the agi-bin
> directory: 
> 
> ########## START CODE #############
> #!/usr/bin/perl -w
> use strict;
> use Asterisk::AGI;
> $AGI = new Asterisk::AGI;
> my %input = $AGI->ReadParse();
> 
> my $number=$ARGV[0];
> $number=~s/-//g;
> $number=~s/ //g;
> $number=~s/\(//g;
> $number=~s/\)//g;
> 
> print $AGI->set_variable('MyNumber',"$number");
> 
> exit;
> 
> ####### END CODE ########

Depending on how many calls per second you want to perform, 
some dialplan magic might be cheaper than starting up a 
perl process. 

I'd write a diaplan macro for this. If the numbers are in a 
fixed format (4th character is a -, 7th character is a -, 
etc), then it's really simple. 

Something like this:

exten => s,1,SetVar(strPart1 = ${myNumber:0:3}
exten => s,2,SetVar(strPart2 = ${myNumber:4:3}
exten => s,3,SetVar(strPart3 = ${myNumber:7:3}
exten => s,4,SetVar(myNumber = $strPart1$strPart2$strPart3

But I'm using quite an old Asterisk, so current syntax might 
be a little different, but the Wiki suggests this still works.

-- 
Andreas Sikkema                     bbned NV
Van Vollenhovenstraat 3    3016 BE Rotterdam
t: +31 (0)10 2245544  f: +31 (0)10 413 65 45



More information about the asterisk-users mailing list