Forum Discussion
Mike_Finney_119
Nimbostratus
Sep 06, 2013iRule regex to normalize phone numbers?
Been searching but no luck so far looking for a iRule with a regex or some other method to normalize phone numbers from AD for use to pass to an SMS gateway.
I have adapted the method here: https://...
Kevin_Stewart
Employee
Sep 09, 2013One more thing. Because you originally asked about a regex function:
% set num1 "1234567890"
% set num2 "123-456-7890"
% set num3 "123.456.7890"
% set num4 "123 456 7890"
% set num5 "(123) 456-7890"
% set num6 "123foo456bar7890"
% time { regsub -all {\D} $num1 "" newval; puts $newval }
1234567890
26 microseconds per iteration
% time { regsub -all {\D} $num2 "" newval; puts $newval }
1234567890
29 microseconds per iteration
% time { regsub -all {\D} $num3 "" newval; puts $newval }
1234567890
31 microseconds per iteration
% time { regsub -all {\D} $num4 "" newval; puts $newval }
1234567890
37 microseconds per iteration
% time { regsub -all {\D} $num5 "" newval; puts $newval }
1234567890
32 microseconds per iteration
% time { regsub -all {\D} $num6 "" newval; puts $newval }
1234567890
35 microseconds per iteration
% time { puts [string map {"." "" " " "" "-" "" "(" "" ")" "" "+" ""} $num3] }
1234567890
45 microseconds per iteration
The "\D" regex option used in regsub will replace ANY non-numeric character (see num6), so it'll technically do a better job, and is more flexible than the string map version.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects