Skip to content

Instantly share code, notes, and snippets.

@CreativeNotice
Created October 24, 2014 16:20
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 CreativeNotice/9ebe66692320d2c6d053 to your computer and use it in GitHub Desktop.
Save CreativeNotice/9ebe66692320d2c6d053 to your computer and use it in GitHub Desktop.
Format US phone number.
public string function formatPhoneNumber(string phone){
var clean_number = Right( ReReplaceNoCase(arguments.phone, "[^\d]", "", "ALL"), 10);
if( Len(clean_number) == 10){
return '('& Left(clean_number,3) &') '& Mid(clean_number,4,3) &'-'& Right(clean_number,4);
}else{
throw('Phone number is to short.', 'InvalidArgument');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment