Skip to content

Instantly share code, notes, and snippets.

@asimmittal
Created February 12, 2017 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asimmittal/3b4d97550759ceb1ef018700238fb773 to your computer and use it in GitHub Desktop.
Save asimmittal/3b4d97550759ceb1ef018700238fb773 to your computer and use it in GitHub Desktop.
/*******************************************************
* 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