Liveupdate phone number forms and test for international numbers
Regular expressions are a quicker way to get it done. Here's a naïve implementation that's (I believe) functionally equivalent to yours:

var mask = function (content) {
  var val = content.value.replace(/[^\d]/g, ''); // Remove anything that's not a digit
  if( val.length &lt;= 10 ) { // US number
    content.value = val.replace(/^(\d{3})(\d{3})(\d*)$/, '($1) $2-$3');
  } else { // Other
    content.value = val.replace(/^(\d{2})(\d{3})(\d{3})(\d*)$/, '+$1 ($2) $3-$4');
  }
};


Here's a live demo

But this is far, far from perfect. There are many, many things to consider.

For starters, non-US numbers aren't necessarily longer than US ones. My own number is just 8 digits (or 10, if you count the country digits - or 12 if you use "00xx" instead of "+xx" for the country code). So if I wrote my phone number (as I normally would) as "+xx xx xx xx xx", it'd be formatted as a US number - which it isn't. If I wrote "00xx xx xx xx xx", I'd get "+00 ...", which is also wrong since it's an invalid country code.

On top of that, there's a ton of different local conventions for how to write phone numbers.

Point is that you can't go by the phone-number-length alone.

Regardless of how far you want to go with it, though, regular expressions will come in handy. Here's a nice interactive reg exp demo/tester to get you started.