Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created April 2, 2014 14:50
Show Gist options
  • Save dhigginbotham/9935738 to your computer and use it in GitHub Desktop.
Save dhigginbotham/9935738 to your computer and use it in GitHub Desktop.
This just doesn't feel right...
var app = app || {};
app.filter('prettyPhone', function () {
return function (input) {
input = input || null;
if (input) {
if ((input[0] == '(') || (!~input.indexOf('-'))) {
return input;
} else {
var area = [],
three = [],
four = [];
for (var i=0;i<input.length;++i) {
if (i <= 2) {
area.push(input[i]);
continue;
}
if (i <= 5) {
three.push(input[i]);
continue;
}
if (i <= 9) {
four.push(input[i]);
continue;
}
}
var pretty = '(' +
area.join('') +
') ' +
three.join('') +
'-' +
four.join('');
return pretty;
}
}
return input;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment