-1

I am trying to take a 10 digit phone number (1234567890) that is returned from the database and format it to render on the view page as (123) 546-7890.

Is the best way to do that coming from the database to the view, or to take the 10 digits from the user and format it going into the database?

Thanks for responding to the newb question.

tereško
  • 58,060
  • 25
  • 98
  • 150
Kevin Schultz
  • 886
  • 3
  • 20
  • 42
  • Possible duplicate of [How do you format a 10 digit string into a phone number?](http://stackoverflow.com/questions/2089923/how-do-you-format-a-10-digit-string-into-a-phone-number) – jww Aug 16 '14 at 07:07

3 Answers3

1

It makes more sense to format it on the view. Keep the data structure standard and simple in the DB. Let your view control the presentation.

Panda_Claus
  • 103
  • 9
1

you could use the substring function:

'(' + substr(first three digits) + ')' + substr(middle three digits) + '-' + substr(last four)
ItalianStallion
  • 296
  • 2
  • 4
  • 13
  • I tried to do: RetData.PhoneCell = string.Format("{0:(###) ###-####}", double.Parse(s.PhoneCell)); where RetData is the value returned form the db. – Kevin Schultz Aug 15 '14 at 19:56
0

If you are doing any sorting it would be wise to format each group of digits (like the area code) into their own column going into the table.

Bradley Smith
  • 39
  • 2
  • 5