Phone Number Validation: A Cautionary Tale

Aug 26, 2016

We recently received a ticket for a project requesting phone number validation in some forms. Seems like a simple enough problem to solve, right?

Well, it’s not. Even with existing libraries that claim to handle phone validation, the more general the validation becomes, the more cumbersome it gets for both developers and users.
The library we attempted to implement, for example, required users to select a country code before entering their phone number.
However, if a user enters the country code with the phone number, the result is invalid because the library adds the country code before validating.
Of course at a certain point, you can’t be too concerned about things like users’ formatting preferences or whether or not extensions should be allowed if you want to ensure phone numbers are valid.
But the point is, before realizing we would have to rewrite a core feature of a third-party software to implement validation on a handful of other forms, 3 days had been wasted trying to implement basic phone number validation.

So the lesson of the story is: if you’re going to go crawling down a rabbit hole, see if you can find a map of it first.

RECENT POSTS

Meet Sourcetoad, a 2023 Best Places to Work honoree

Meet Sourcetoad, a 2023 Best Places to Work honoree

Tampa Bay Business Journal — April 26, 2023 Sourcetoad has been selected as a 2023 Best Places to Work! We are thrilled to be among Tampa's top workplaces for the fourth year in a row, and we are grateful to each of our Toads for making Sourcetoad such a fantastic...

This Year in FinTech: Trends to Watch in 2023

This Year in FinTech: Trends to Watch in 2023

The financial services industry experienced rapid digitization throughout the COVID-19 pandemic, and growth of the financial technology market is expected to continue in 2023. The global fintech market grew to $158.9 billion in 2022, and projections estimate it will...

2023 Top HealthTech Trends

2023 Top HealthTech Trends

Technological innovation has played a vital role in the transformation and growth of the healthcare industry. Not only is the medical space an early adopter of emerging technologies, HealthTech is currently one of the fastest-growing industries worldwide. The global...