Last active
October 2, 2017 17:05
-
-
Save cbfn/78ed33e6c706cb0a480b414e4c66aca5 to your computer and use it in GitHub Desktop.
Phone format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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