Are there best practices for validating, recording AND formatting phone numbers?
Thanks for the link to AN answer regarding AN ELEMENT of my question: a regex for validating. But please recognize that it does not answer the question that was asked. There are no doubt countless suggestions for validating, recording and formatting phone numbers; many of which are highly rated. However, since this is a common area that a multitude of developers have wrestled with for a long period of time, I asked if there are generally accepted best practices for the whole package.
Please read and respond to the stated question:
Are there best practices for validating, recording and formatting phone numbers?
- Starting with the data element, are phone numbers better stored as integers or strings (or something else)?
- Next, should delimiters be stored with the numbers or stripped out?
(In other words, should (212) 555-1212 be recorded as 2125551212 and then formatted appropriately in a view?) - Next, what's the best way to deal with formatting alternatives in
different countries? Perhaps if the country code was recorded in a
separate field, a
SWITCH
statement could be used to select the right formatting for the view (or validation) of the phone number itself. - Finally, are there good examples of regular expressions or other methods for validating phone number inputs?
I recognize the this is really a collection of questions, each of which likely has opinions scattered all over SO and the web. Since validating, recording and displaying formatted phone numbers is such a common task, it seems like there should be some standard methodologies or best practices; and my question is, "Are there generally accepted practices, and where can I find them?"