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

Chris Wade clwade at sparco.com
Mon Sep 26 13:35:38 MST 2005


Nathan Pralle 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.
> 
> Scott,
> 
> This would be darned easy to do with the AGI and a perl script.

<snip>

> $number=~s/-//g;
> $number=~s/ //g;
> $number=~s/\(//g;
> $number=~s/\)//g;

change this to be...

$number =~ s/\D//g;  # \D is regexp for non-digit

...or if some letters were ok to dial (ABCD) you could do...

$number =~ s/(?i)[^\dabcd]//g;  # \d is regexp for digits
                                 # (?i) make the express case-insensitive
                                 # the [^...] construct effectively means
                                 #   anything not specified between [ & ]


my $two_cents = 'a grain of salt';
-- 
Christopher L. Wade, CCNA, CCDA, CQS-CIPTES, CQS-CWLSS




More information about the asterisk-users mailing list