Created
September 23, 2014 19:30
-
-
Save NiCkEl5/80279bfa4d6d417a1c88 to your computer and use it in GitHub Desktop.
later
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 phoneNumberFormat(phone){ | |
phoneAux = phone.replace(/\D/g, '') | |
if (phoneAux.length == 10){ | |
parsedPhone = phoneAux.substr(0,3) +"-"+phoneAux.substr(3,3)+"-"+phoneAux.substr(6,phoneAux.length) | |
} | |
else if(phoneAux.length == 11 && phoneAux.substr(0,1) == "1"){ | |
parsedPhone = phoneAux.substr(1,3) +"-"+phoneAux.substr(4,3)+"-"+phoneAux.substr(7,phoneAux.length) | |
} | |
else{ | |
parsedPhone = phoneAux | |
} | |
return parsedPhone | |
$("#") | |
console.log(parsedPhone) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment