Created
November 19, 2019 18:59
-
-
Save jrmarqueshd/42d8c8e7eb7041bcefd0562ccbd433ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const input = document.getElementById("input"); | |
function telephone(v) { | |
v = v.replace(/\D/g, ""); | |
v = v.replace(/^(\d\d)(\d)/g, "($1) $2"); | |
v = v.replace(/(\d{4})(\d)/, "$1-$2"); | |
return v | |
} | |
input.addEventListener("input", () => { | |
let value = telephone(input.value); | |
input.value = value; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment