What is the correct way to store phone number data after applying a new mask for user input (example for UK; 44 07400 123456) if the type of the existing column is character varying(32)? Does storing it as it is generated by mask has a drawbacks (especially space characters)?

In other words, what are some pros and cons of storing it as formatted or unformatted might be better to asking for my case, since I'm not dealing with the type of the column and I'm going to stay with the same type. Especially, what I'm really care about is that is, what would be best practice? +4407400123456 or 44 07400 123456 (with spaces).

  • Placement of "spaces" is dependent of the country, so I feel this is added complexity for nothing. You should store it as international format, which is ITU-T E.164 and looks like +CC.DDDDDDDDD . You are free to expose that to end clients the way you want but content in DB should be normalized. Depending on your requests on it you may decide to store each part separately (but you may also need to handle phone number extension...) – Patrick Mevzek Apr 28 '18 at 23:25

Generally speaking, the presentation layer is where formatting should occur. If spaces are only useful for presentation to the user, then reformat the phone number in the client app, and remove the spaces prior to storing them, since that will save space in the database.

Some of the questions about how to store phone numbers have been asked and answered here already. See this and this.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.