-1

JS newbie here! Thanks in advance for the help!

I am trying to format a phone number in Zapier. The data is coming in from a webhook and is typically of the format '2223334444'. I need to confirm this formatting and then add a 1 to the front of the number for use in the Twilio integration. My attempted code is attached

jv2pt0
  • 3
  • 1

2 Answers2

0

You should be using regex:

function convertPhone(phone)
{
    if (!phone.match(/1?2{3}3{3}4{4}/)
        return null;
     // check in case humber has a prefix of 1:
     return phone.match(/$1.+/)? phone: 1 + phone;

}
Amir H. Bagheri
  • 1,416
  • 1
  • 9
  • 17
0

You can actually format a phone number with the built-in Formatter: https://zapier.com/help/formatter/. It's a bit better than running it through a code step because the phone number will be validated and formatted according to whatever format/standard you select, even when the input format varies.

Juan Vazquez
  • 533
  • 3
  • 8