Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*******************************************************
* formatPhoneText
* returns a string that is in XXX-XXX-XXXX format
*******************************************************/
function formatPhoneText(value){
value = this.replaceAll(value.trim(),"-","");
if(value.length > 3 && value.length <= 6)
value = value.slice(0,3) + "-" + value.slice(3);
else if(value.length > 6)
value = value.slice(0,3) + "-" + value.slice(3,6) + "-" + value.slice(6);
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment