Remove unwanted charcters from a string

Discussion in 'ASP .Net' started by Chris Kettenbach, Jul 20, 2005.

  1. Good Morning,
    I have a text box on a webform I use to display a phone number. The
    database field does not contain parentheses or hyphens. I want the use to
    be able to change the textbox text and be able to click an update button to
    save the changes to the database? My question is how do I remove the
    unwanted characters and save that value to the database? I use a function
    in the text attribute of the control to set the display value. like
    text="<%# formatphone(databinder.eval(Container.DataItem, "phone")) %>' and
    this works great. Basically i want to undo this when saving to the
    database. I wanted to use a regex object but I am not familiar enough with
    it to code it correctly. Any advise would be great. Thanks everyone!!

    Regards,
    Chris
    Chris Kettenbach, Jul 20, 2005
    #1
    1. Advertising

  2. I figured it out. This works great!

    Function unformatphone(phone as string) as string
    dim val as string
    val = regex.replace(phone, "\D", "")
    return val
    End Function

    \D is any non-digit character
    Sweet

    "Chris Kettenbach" <> wrote in message
    news:...
    > Good Morning,
    > I have a text box on a webform I use to display a phone number. The
    > database field does not contain parentheses or hyphens. I want the use to
    > be able to change the textbox text and be able to click an update button
    > to save the changes to the database? My question is how do I remove the
    > unwanted characters and save that value to the database? I use a function
    > in the text attribute of the control to set the display value. like
    > text="<%# formatphone(databinder.eval(Container.DataItem, "phone")) %>'
    > and this works great. Basically i want to undo this when saving to the
    > database. I wanted to use a regex object but I am not familiar enough
    > with it to code it correctly. Any advise would be great. Thanks
    > everyone!!
    >
    > Regards,
    > Chris
    >
    Chris Kettenbach, Jul 20, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. peelman
    Replies:
    1
    Views:
    14,186
    Karl Seguin
    Oct 18, 2005
  2. brandons of mass destruction

    charcters styles via html

    brandons of mass destruction, Jul 26, 2003, in forum: XML
    Replies:
    1
    Views:
    430
    Steven Dilley
    Jul 30, 2003
  3. ABHIJIT B

    ASP.NET 2.0 TextBOx WildCard charcters

    ABHIJIT B, Feb 20, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    392
    ABHIJIT B
    Feb 20, 2008
  4. charvind

    Accented charcters in Asp.net

    charvind, Aug 13, 2008, in forum: .NET
    Replies:
    0
    Views:
    453
    charvind
    Aug 13, 2008
  5. Paul Jørstad

    Control charcters in form input field

    Paul Jørstad, Sep 17, 2003, in forum: Javascript
    Replies:
    4
    Views:
    244
    asdf asdf
    Sep 19, 2003
Loading...

Share This Page