Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Phone Number Format

    Ken,

    your regex has to be mapped to the INPUT, not the output. by including
    parens and dashes in the regex, you are guaranteeing that the normalized
    version of the number ("1234567890") will not be matched.

    regex string:
    (\d\d\d)(\d\d\d)(\d\d\d\d)

    replacement string
    ($1) $2-$3

    applied to this input:
    1234567890

    generates:
    (123) 456-7890


    also, a tip for you, and all other regex hackers: get this tool:
    [url]http://www.organicbit.com/regex[/url]

    Free, small, easy, useful.

    -Dino

    "Ken" <k_schallmo@hotmail.com> wrote in message
    news:OD9wzgfVDHA.2344@TK2MSFTNGP09.phx.gbl...
    > How do apply a phone number format to a string? I have the regular
    > expression, but have been unable to figure out how to apply the expression
    > to a string from a database. I am not trying to validate the data, but
    > display the output from the database in a nice format.
    > Phone number string = 1234567890
    > Regular expression = ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
    > Desired output = (123) 456-7890
    >
    > Thank you,
    > Ken
    >
    >

    Dino Chiesa [MSFT] Guest

  2. Similar Questions and Discussions

    1. Format Phone Number
      I have a text feild (homephone) in MSAccess that hold phone numbers (410)543-3333 When I display these in a <CFOUTPUT>#HOMEPHONE#<\CFOUTPUT> the...
    2. I need to dial phone number from my browser
      Hello, Did you ever have any luck with this? I need to do the same thing and am having no luck. Thanks, Steve
    3. query match for phone number
      Why order by phone number? You need to have a formatted phone number or sorting by it will not work out very well.
    4. Format Phone Number String in Datagrid Column
      Greetings, I have a 10 digit phone number stored as a string in a SQL server table. My datagrid currently displays it as 1234567890, but I would...
    5. Phone Format (770) 123-1234
      Hi, How do I apply phone format in a string field? for example (770) 123-1234. Please let me know. Thanks. Eddy
  3. #2

    Default Re: Phone Number Format

    From MSDN:

    Double myDouble = 1234567890;
    String myString = myDouble.ToString( "(###) ### - ####" );
    // The value of myString is "(123) 456 - 7890".


    --
    Chris Jackson
    Software Engineer
    Microsoft MVP - Windows XP
    Windows XP Associate Expert
    --
    "Ken" <k_schallmo@hotmail.com> wrote in message
    news:OD9wzgfVDHA.2344@TK2MSFTNGP09.phx.gbl...
    > How do apply a phone number format to a string? I have the regular
    > expression, but have been unable to figure out how to apply the expression
    > to a string from a database. I am not trying to validate the data, but
    > display the output from the database in a nice format.
    > Phone number string = 1234567890
    > Regular expression = ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
    > Desired output = (123) 456-7890
    >
    > Thank you,
    > Ken
    >
    >

    Chris Jackson Guest

  4. #3

    Default Re: Phone Number Format

    hi ken

    this will work ..
    Response.Write(Format(Convert.ToDouble(txtPhone.Te xt), "(###) ###-####"))

    Hope it helps
    Shahram


    "Ken" <k_schallmo@hotmail.com> wrote in message
    news:OD9wzgfVDHA.2344@TK2MSFTNGP09.phx.gbl...
    > How do apply a phone number format to a string? I have the regular
    > expression, but have been unable to figure out how to apply the expression
    > to a string from a database. I am not trying to validate the data, but
    > display the output from the database in a nice format.
    > Phone number string = 1234567890
    > Regular expression = ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
    > Desired output = (123) 456-7890
    >
    > Thank you,
    > Ken
    >
    >

    Shahram Khosraviani Guest

  5. #4

    Default Re: Phone Number Format

    Hi Dino,

    I tried that code, but it didn't work. Here is some code snippet of mine.
    Please correct me. Thanks.

    <Columns>
    <asp:HyperLinkColumn Text="Smoking History"
    DataNavigateUrlField="legal_entity_sk"
    DataNavigateUrlFormatString="SmokingHistoryList.as px?legal_entity_sk={0}"
    DataTextField="legal_entity_sk" HeaderText="Smoking
    History"></asp:HyperLinkColumn>
    <asp:BoundColumn DataField="cf_FullName"
    HeaderText="Name"></asp:BoundColumn>
    <asp:BoundColumn DataField="user_id" HeaderText="User
    ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="cf_CompanyName"
    HeaderText="Company"></asp:BoundColumn>
    <asp:BoundColumn DataField="e_mail_work" HeaderText="Email
    (Work)"></asp:BoundColumn>
    <asp:BoundColumn DataField="e_mail_home" HeaderText="Email
    (Home)"></asp:BoundColumn>
    <asp:BoundColumn DataField="phone_business" HeaderText="Phone (Work)"
    DataFormatString="(\d\d\d)(\d\d\d)(\d\d\d\d)"></asp:BoundColumn>
    <asp:BoundColumn DataField="phone_home" HeaderText="Phone
    (Home)"></asp:BoundColumn>
    </Columns>

    Eddy

    "Dino Chiesa [MSFT]" <dinoch@microsoft.com> wrote in message
    news:unrjBrfVDHA.208@tk2msftngp13.phx.gbl...
    > Ken,
    >
    > your regex has to be mapped to the INPUT, not the output. by including
    > parens and dashes in the regex, you are guaranteeing that the normalized
    > version of the number ("1234567890") will not be matched.
    >
    > regex string:
    > (\d\d\d)(\d\d\d)(\d\d\d\d)
    >
    > replacement string
    > ($1) $2-$3
    >
    > applied to this input:
    > 1234567890
    >
    > generates:
    > (123) 456-7890
    >
    >
    > also, a tip for you, and all other regex hackers: get this tool:
    > [url]http://www.organicbit.com/regex[/url]
    >
    > Free, small, easy, useful.
    >
    > -Dino
    >
    > "Ken" <k_schallmo@hotmail.com> wrote in message
    > news:OD9wzgfVDHA.2344@TK2MSFTNGP09.phx.gbl...
    > > How do apply a phone number format to a string? I have the regular
    > > expression, but have been unable to figure out how to apply the
    expression
    > > to a string from a database. I am not trying to validate the data, but
    > > display the output from the database in a nice format.
    > > Phone number string = 1234567890
    > > Regular expression = ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
    > > Desired output = (123) 456-7890
    > >
    > > Thank you,
    > > Ken
    > >
    > >
    >
    >

    Eddy Soeparmin Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139