Skip to content

Instantly share code, notes, and snippets.

@cbfn
Last active October 2, 2017 17:05
Show Gist options
  • Save cbfn/78ed33e6c706cb0a480b414e4c66aca5 to your computer and use it in GitHub Desktop.
Save cbfn/78ed33e6c706cb0a480b414e4c66aca5 to your computer and use it in GitHub Desktop.
Phone format
function formatPhone(phone) {
var regex = phone.match(/(\d{3})(\d{4})(\d+)/);
return '(' + regex[1] + ') ' + regex[2] + '-' + regex[3];
}
var phone = '4031234789';
formatPhone(phone);
// Result: (403) 1234-789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment