Answered by:
Display phone number from webform as (###) ###-####

Question
-
User1044989675 posted
I have a webform that contains a text box with a phone number, this form get emailed to an administrator, how do I get the phone number to display as (###) ###-#### in the email?
MailMessage message = new MailMessage(); message.To.Add("me@domain.com"); message.From = new MailAddress("NoReply@domain.com", "Do Not Reply"); message.Body = (tbClient.Text + "\nName: " + txt_name.Text + "\nCompany: " + txt_company.Text + "\nAddress: " + txt_address.Text + "\nCity: " + txt_city.Text + "\nState: " + ddl_state.SelectedItem + "\nZip: " + txt_zipcode.Text + "\nPhone: " + txt_phone.Text + "\nEmail: " + txt_email.Text + "\nUsername: " + txt_username.Text + "\nPass: " + txt_pass.Text); SmtpClient smtp = new SmtpClient("mail.domain.com"); smtp.Credentials = new System.Net.NetworkCredential("me@domain.com", "pass"); smtp.Port = 25; message.Priority = MailPriority.Normal; smtp.Send(message);
code behind.
Wednesday, March 13, 2013 12:36 PM
Answers
-
User-1360095595 posted
String.Format(), or .ToString() specifying your desired format.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, March 13, 2013 12:43 PM -
User-1716253493 posted
int phone = int.Parse( txt_phone. Text ); then use phone.ToString(format)- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, March 13, 2013 1:08 PM
All replies
-
User-1360095595 posted
String.Format(), or .ToString() specifying your desired format.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, March 13, 2013 12:43 PM -
User1044989675 posted
so it would look like:
String.Format(txt_phone.Text("(###) ###-####")
Wednesday, March 13, 2013 12:48 PM -
User533502567 posted
String.Format("{0:(###) ###-####}", txt_phone.Text);
Wednesday, March 13, 2013 12:54 PM -
User-1716253493 posted
your data should number or convert it to number then use .ToString (" (###) ###-####")Wednesday, March 13, 2013 12:55 PM -
User1044989675 posted
?
can you show me an example, I am very confused
Wednesday, March 13, 2013 1:03 PM -
User-1716253493 posted
int phone = int.Parse( txt_phone. Text ); then use phone.ToString(format)- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, March 13, 2013 1:08 PM