Created
January 2, 2018 18:39
-
-
Save devalexandre/049cbbdd5c78dffc2c4907b1e84b28c5 to your computer and use it in GitHub Desktop.
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 mtel(v) | |
{ | |
v=v.replace(/\D/g,""); //Remove tudo o que não é dígito | |
var res = v.replace(/\D/g,""); | |
//v=v.replace(/^(\d{2})(\d)/g,"($1) $2"); //Coloca parênteses em volta dos dois primeiros dígitos | |
//res = "(" + res.substring(0,2) + ")"; | |
if(res.length == 11) { | |
v = v.replace(/(\d{2})(\d{5})(\d{4})$/, "($1)$2-$3"); //Coloca hífen entre o quarto e o quinto dígitos | |
console.log(v); | |
} | |
else{ | |
v = v.replace(/(\d{2})(\d{4})(\d{4})$/, "($1)$2-$3"); | |
console.log(v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment