Skip to main content

Hey there, I am trying to use Code by Zapier for replacing few characters from a phone number data string.

This is the code given to me by a developer to do that (both python and JavaScript for it exist)

string = string.replace("+", "").replace("-", "").replace(" ", "")

 This is the screenshot of what I did in Zapier

 

I am not a developer so not sure how this works, could anyone tell me what I did wrong here

I’ve provided solutions in both Javascript and Python below, but I do have a couple of questions for you to consider:

  1. This will replace all instances of “ “, “+”, and “-” with an empty character. It appears the data you have coming from step 2 is a long list of numbers. Are they separated by commas? If not, you will end up with a long string of digits, such as 18888888888133333333331555555555517777777777
  2. In the code below, I stuck with the variable name “Name” that you declared above. But I would consider changing it to something like “phoneNumbers” or “digitsOnly”. This will help you know what the code is referring to if you reference it later. Either way, you can delete the grayed out comments.

For Javascript, use this:

var name = inputData.phone.replace(/\s|\+|-/g, ""); // I recommend replacing "name" with "digitsOnly"

output = O{name}]; // Same note here

If you’d like to stick with Python, use this:

Name = input_datag'phone'].replace("+", "").replace("-", "").replace(" ", "") # I recommend replacing "Name" with "digitsOnly"

output = t{"Name": Name}] # I recommend replacing the first "Name" with "Phone Number List" and the second "Name" with "digitsOnly"

 


Reply