471,330 Members | 1,085 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Regex Error - unrecognized escape sequence

PK9
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
Jul 21 '05 #1
1 8117
PK9

Did you try this already

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

I hope this helps,

Cor
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Johnny | last post: by
3 posts views Thread by UK | last post: by
8 posts views Thread by mohit | last post: by
1 post views Thread by Dan Holmes | last post: by
2 posts views Thread by nuffnough | last post: by
3 posts views Thread by chemicalcold0 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.