Hey everyone! I’m pretty new to JavaScript and could really use some guidance.
I’m working with a Zapier workflow where phone numbers come through a webhook in this format: 2223334444 (just 10 digits with no formatting). What I need to do is validate that the number follows this pattern and then add a 1 at the beginning so it becomes 12223334444 for my Twilio setup.
I’ve been trying to write some code to handle this but I’m stuck. Has anyone dealt with similar phone number manipulation in Zapier before? I’d appreciate any tips or code examples that might help me get this working properly.
Thanks for any help you can provide!
I encountered a similar issue when integrating Twilio with Zapier. To validate the 10-digit phone format, a regex like /^\d{10}$/ is helpful, as it will prevent any non-compliant numbers from proceeding. Once validation passes, concatenate ‘1’ at the start for Twilio’s requirements. I also recommend logging any numbers that fail this check; it aids in spotting issues stemming from varied input formats. Be mindful of leading zeros, as they can be lost if treated as integers.
This is pretty straightforward once you get it. I hit this same issue six months ago with automated SMS notifications. The main thing is handling edge cases - webhooks sometimes send numbers with spaces or dashes that you need to clean first. I use phoneNumber.replace(/\D/g, '') to strip non-digits before checking length. Then verify it’s exactly 10 characters and add the ‘1’. One gotcha I learned the hard way: some systems send international numbers inconsistently, so check if numbers already start with ‘1’ to avoid creating ‘112223334444’. Also test numbers starting with zero since those behave weird in JavaScript.
just dealt with this last week! quick tip - use let newNumber = '1' + phoneNumber after verifying it’s 10 digits. works perfectly in zapier’s code step. don’t overthink it - regex validation is fine but honestly phoneNumber.length === 10 does the job if you’re keeping it simple.