Regex Error - unrecognized escape sequence

G

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;
}
 
C

Cor Ligthert

PK9

Did you try this already

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

I hope this helps,

Cor
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top