Finding a string in a phone number
How to find a string in a phone number and replace it. For example, given the string 'code' and the phone number '8556212633 this function will return back '855621code'
function alphabetizeNumber(number,str) {
var x = str.toString()
.replace(/a|b|c/gi,'2')
.replace(/d|e|f/gi,'3')
.replace(/g|h|i/gi,'4')
.replace(/j|k|l/gi,'5')
.replace(/m|n|o/gi,'6')
.replace(/p|q|r|s/gi,'7')
.replace(/t|u|v/gi,'8')
.replace(/w|x|y|z/gi,'9');
return(number.toString().replace(x,str));
}
@andersbrownwort did most/all of the work on this. I just wanted to make sure it was recorded somewhere so I don't forget it later.
Written by Scott Barstow
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#