Regex Error - unrecognized escape sequence

Discussion in 'Microsoft Dot NET' started by Guest, Mar 31, 2005.

  1. Guest

    Guest Guest

    I'm trying to validate input from a textbox in the code-behind of my page.
    I don't want to use any validator controls for this, I'd like to do it all in
    the code behind. However, I'm getting an "unrecognized escape sequence"
    compile error. Can someone please help me determine the correct regular
    expression statement? I'm trying to validate that the textbox only contains
    "Safe" characters (digits, letters, spaces, periods, etc).

    Here is my code:

    //Validate for safe characters
    Regex r = new Regex("^[a-zA-Z0-9\\s.\\-]+$");

    if (!r.IsMatch(txtUVNONumber.Text))
    {
    lblErrorMessage.Text = "Invalid entry for UVNO Number";
    lblErrorMessage.Visible = true;
    }
    --
    PK9
     
    Guest, Mar 31, 2005
    #1
    1. Advertisements

  2. Guest

    Cor Ligthert Guest

    PK9

    Did you try this already

    Regex r = new Regex(@"^[a-zA-Z0-9\\s.\\-]+$");

    I hope this helps,

    Cor
     
    Cor Ligthert, Mar 31, 2005
    #2
    1. Advertisements

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. Chris R. Timmons

    Re: Error in c# project: Unrecognized escape sequence

    Chris R. Timmons, Jul 7, 2003, in forum: Microsoft Dot NET
    Replies:
    2
    Views:
    74,795
    Madhan Babu
    Dec 12, 2011
  2. Evgeny Zoldin

    How to convert HTML escape-sequence into String?

    Evgeny Zoldin, Nov 16, 2003, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    273
    Erik Frey
    Nov 16, 2003
  3. Sepham.com
    Replies:
    0
    Views:
    200
    Sepham.com
    Nov 22, 2004
  4. Guest

    unrecognized parameters against virtual field

    Guest, May 4, 2005, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    151
    Guest
    May 4, 2005
  5. toddc612

    Unrecognized attribute 'requirePermission' error.

    toddc612, Nov 21, 2005, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    3,382
    toddc612
    Nov 21, 2005
Loading...

Share This Page