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

The Agile Manifesto in Practice: Part 1

The Agile Manifesto in Practice: Part 1

  How Sourcetoad Values People Over Process The software development process can involve a lot of uncertainty for both development teams and clients alike, especially in the early phases of a project. How can the long-term vision of an application be balanced...

What to Consider When Building HIPAA-Compliant Software

What to Consider When Building HIPAA-Compliant Software

In 1999, the Department of Health and Human Services (HHS) passed the Health Insurance Portability and Accountability Act (HIPAA) as a measure to protect personal health information (PHI) and allow people control of their healthcare records. The HITECH Act was enacted...

The Evolution of Buy Now, Pay Later in eCommerce: Part 2

The Evolution of Buy Now, Pay Later in eCommerce: Part 2

In Part 1, we talked about the rapid growth of Buy Now, Pay Later (BNPL) and discussed its expansion across industries. In Part 2, we will consider how impending regulation may shake up the short-term lending space.   Impending Regulation of BNPL While consumers...