O
29

Pro tip: don't blindly copy paste code from Stack Overflow without checking what it actually does first

I copied a 3-line regex snippet from a 2014 forum post to validate email addresses in my signup form and ended up accidentally blocking over 200 users from 8 different countries because it was too strict, so now I always test any borrowed code against a real dataset before pushing it live.
2 comments

Log in to join the discussion

Log In
2 Comments
emmam67
emmam672d ago
Regex is like a loaded gun honestly. I once used a regex from a 2009 tutorial to clean up phone numbers from a user list and it stripped out the plus sign from international codes, so everyone from the UK got their numbers turned into gibberish. It was for a small charity mailing list, not like a huge operation, but still felt terrible when people complained they couldn't get the updates. And the worst part was the original post had like 400 upvotes and nobody in the comments mentioned the plus sign issue at all. So now I keep a little test file with a hundred real sample inputs and run any borrowed code through it, plus a few edge cases I know are weird. It's saved me from breaking things with date formatters and password rules more times than I can count.
2
leep89
leep892d ago
Oh man, this is way too real! I grabbed a jQuery plugin from some random blog to add smooth scrolling to my site and it completely broke the nav menu on mobile devices. Took me three days to figure out why half my users couldn't click anything on their phones. The plugin was loading some old version of jQuery that conflicted with everything else. Now I always load a snippet into a test branch first and watch the console for errors before I even think about merging it. Regex stuff is scary too - I once used a URL validator that was so strict it rejected perfectly valid Brazilian domains with accents.
1