Validating Social Media URLs in Swift
Article Summary
Alvin Matthew Pratama from Tokopedia tackles a deceptively complex problem: validating social media URLs when each platform has wildly different URL structures. Regex alone won't cut it.
When Tokopedia launched their affiliate program, they needed users to register social media accounts. The challenge? YouTube alone has three different valid URL patterns for user pages. The team needed a flexible, maintainable solution that wouldn't become a regex nightmare.
Key Takeaways
- SuperValidator splits URLs into components: protocols, paths, domains, and query parameters
- Handles platform quirks like YouTube's /user/, /c/, and /channel/ paths automatically
- Open source library supports Instagram, TikTok, Twitter, and more out of the box
- Returns detailed error types for user feedback, not just pass/fail validation
Tokopedia open sourced SuperValidator, an option-based Swift library that validates social media URLs by breaking them into customizable components instead of brittle regex patterns.
About This Article
Tokopedia's affiliate program needed to validate social media URLs from different platforms. Each platform had its own domain structure and URL format, which made regex solutions hard to maintain and prone to errors.
Alvin Matthew Pratama's team built SuperValidator, a Swift library that breaks URL validation into separate, customizable parts. Instead of writing complex regex patterns, developers can now configure protocols, paths, domain whitelists and blacklists, and FQDN checks as needed.
SuperValidator is now an open-source library that handles Instagram, TikTok, Twitter, and other platforms. It includes built-in validators for each social media service, so developers can validate platform-specific URLs with a single function call and get detailed error types to show users.