I need help cleaning up a phone number dataset by removing certain characters. My data looks like this:
+1 954-123-4567,+1 813-987-6543,+1 407-555-1234,+1 954-678-9012,+1 813-246-8135,+1 407-864-2973,
The phone numbers contain inconsistent formatting with plus signs, spaces, and dashes that I want to strip out completely. I want to eliminate these three character types:
- Plus signs (+)
- Hyphens (-)
- Spaces
Since Zapier supports both JavaScript and Python in their code blocks, which approach would work best for this task? I’m fairly new to coding in Zapier so any working example would be really helpful. The goal is to have clean numeric phone numbers without any special characters or spacing.
python’s easier if you’re comfortable with it. try phone_data = input_data.get('phone_numbers', '').replace('+', '').replace('-', '').replace(' ', '') then return the cleaned string. i stick with python since the syntax is way more straightforward than regex.
I’ve done similar phone number cleaning in Zapier - JavaScript works great for this. Just use replace() with regex to strip unwanted characters in one line:
let cleanNumbers = inputData.phoneNumbers.replace(/[+\s-]/g, '');
output = [{cleanNumbers: cleanNumbers}];
The regex [+\s-] matches plus signs, spaces, or hyphens. The g flag removes all of them from the string. This processes your whole comma-separated string at once instead of handling each number separately. Works reliably across different formats and won’t cause debugging headaches. Just double-check your input field name matches what’s coming from your previous Zap step.
Both work fine, but I’d go with Python’s translate method for bigger datasets - it’s way faster. Here’s what I use in my Zapier workflows:
import string
phone_string = input_data['phone_numbers']
translation_table = str.maketrans('', '', '+- ')
cleaned_numbers = phone_string.translate(translation_table)
output = [{'cleaned_numbers': cleaned_numbers}]
Translate beats chaining multiple replace calls because it handles all unwanted characters in one pass. I’ve run this on thousands of phone records without hitting timeouts. Just double-check your input field name matches what’s coming from the previous step.