Day 4

Got phone number storage and testing squared away today. Ended up with these columns in the phone table, which feels simple and clean:


Next, I need to connect to Twilio and send the confirmation link. Eventually, I’d like to expire these tokens as well to make the things more secure.

There are a few edge cases to consider when validating US phone numbers, which is where I’m starting. The number might be too long, too short, or it might be formatted strangely. To handle formatting issues, the first thing I do when validating the number is strip out anything non-numeric. This allows the visitor to enter the number in any format that makes sense to them and avoids those weird phone number forms with multiple boxes. If the number is 10 digits long, or 11 digits long and starts with a “1”, then the number is good. Anything else returns an error. Store it with the “+1” at the front for ease of use with Twilio and we’re off to the races.

This is my first time creating a phone-first sign up process. I’d love to hear about anything I missed or how you approached a similar problem.