Using TextExpander to format phone numbers

I added the following javascript snippet to TextExpander:

function formatPhoneNumber(phoneNumberString) {
  var cleaned = ('' + phoneNumberString).replace(/\D/g, '');
  var match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/);
  if (match) {
    return '(' + match[1] + ') ' + match[2] + '-' + match[3];
  }
  return null;
}
formatPhoneNumber(TextExpander.pasteboardText);

Now I can cut a poorly formatted phone number and call my abbreviation (.pnf) to format it, and put it right back into my document.

The javascript came from https://stackoverflow.com/questions/8358084/regular-expression-to-reformat-a-us-phone-number-in-javascript