QA Graphic

Quick Phone Number formating

Use TextExpander to quickly format a phone number.

JavaScriptPhone.jpg

Today's TextExpander tip is a simple tool to convert a phone number into a more readable type of format.

Every once in a while I'll need to convert a nine digit number such as 8004249090 to an easier readable format such as (800) 424-9090.

This is the Javascript snippet that I use in my TextExpander library:

var pnum ="%clipboard";
    var numbers = pnum.replace(/D/g, ''),
        char = {0:'(',3:') ',6:' - '};
    pnum = '';
    for (var i = 0; i < numbers.length; i++) {
        pnum += (char[i]||'') + numbers[i];
    }

I call my abbreviation .pformat.

So, now when I encounter the nine digit number, I can simply copy the number and then type in .pformat and POOF! the format appears.

If you know some basic JavaScript, you can easily change up the function above to make the number display any way you want.

 

Comments

Add Comments

Name:
Comment:

 

About

I find TextExpander, by Smile on My Mac, to be an awesome productivity tool. This past winter, I posted some cool snippets that demonstrate the power of the application. Occasionally, I will post some new snippets that I think will be useful in anyone's TextExpander library.

Schedule

Monday Media Monday
TuesdayQA
WednesdaySnagIt for QA
ThursdayPython
FridayMacintosh
SaturdayInternet Tools
SundayOpen Topic