Phone number formatter formula

Phone number Formatter is a custom formula in Apps Script for Google Sheets that can be used to format phone numbers in a specific way. The formula can be helpful for businesses that deal with phone numbers frequently and need to ensure that they are formatted in a consistent and recognizable way.

The custom formula code for Phone number Formatter can be written as follows:

function formatPhoneNumber(number) {
  if(number.toString().length == 10){
    var formattedNumber = number.toString().replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
    return formattedNumber;
  } else {
    return "Invalid Phone Number";

In this code, the function formatPhoneNumber() takes a phone number as an input and checks if it is a valid 10-digit number. If it is, the code uses regular expressions to format the phone number in a specific way – with parentheses around the area code, a space, and a hyphen between the next set of numbers. If the input is not a valid 10-digit phone number, the function returns an error message.

To use the custom formula, simply enter =formatPhoneNumber(A1) in the cell where you want the formatted phone number to appear, replacing A1 with the cell containing the original phone number.

For example, if cell A1 contains the phone number 1234567890, entering the formula =formatPhoneNumber(A1) in cell B1 will output the formatted phone number (123) 456-7890 in that cell.