I am presently building a website, in PHP, that users will be able to interact with via SMS messaging. Consequently, I need to store their phone numbers in my database. Since I am only allowing SMS interactions in the U.S. right now, I need to check that the submitted phone numbers conform to the U.S. format. Generally, this means a few things: 1
must be the first number, the area code must not begin with 0
or 1
, and the string without the leading 1
must be 10 digits (3 digit area code plus 7 digit number).
Despite all of these requirements, I want users to feel free to enter their number in whatever format they prefer without causing an error.