The title may have been confusing, but please let me explain:
Currently when I am storing phone number with raw digits like 5554441234
. Then in my template I was going to "format" the number into something like 555-444-1234
.
I realized in Django's localflavor
, there is a US phone number field that checks if a string is in XXX-XXX-XXXX
format.
So my question is should I enter the phone number as raw digits then format it in the template or should I enter the phone number in the formatted way using localflavor?
If I choose the latter, would the XXX-XXX-XXXX
format restriction apply even to the database API
level or in the Django admin page?
Store them as entered, only strip surrounding white space if necessary. The way a user formats its number stores semantic information that you do not want to lose by normalizing it. In the US the format XXX-XXX-XXXX
is very common, but other locales use totally different formats. For example, where I live some common formats are: XX-XXX XXX XX
, XXX/XXX XX XX
, +46(0)70-XXX XX XX
and so on ad nausem.
The number displayed to the user should be in the same format as entered, otherwise he or she will think of it as munged or may not even recognize the number if it is formatted in a different style than the user is used to. See also this discussion: http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=6079&ixReplies=6