Cytemax
Cytemax

Reputation: 71

C# Regular Expression - Why some char not in it validate the IsMatch() condition?

I use this regular expression for validating some of my textbox :

Regex re = new Regex("^([äö\x20\x27\x2C\x2D\x5Fò-öà-âù-üç-ï0-9a-zA-Z]+)$");

And when i put "<" or ">" in one of this textBox, my condition shoud be false and not true :)

if (re.IsMatch(TextBox.Text)) /*do something */ else Console.write("error invalid char in textbox")

That's so weird because if i test it with RegexBuddy this two char are not valid, so if someone can help me ;)

Regards,

Cytemax

Upvotes: 1

Views: 356

Answers (1)

Cobusve
Cobusve

Reputation: 1570

Try this:

Regex re = new Regex(@"^([äö\x20\x27\x2C\x2D\x5Fò-öà-âù-üç-ï0-9a-zA-Z]+)$");

If you omit the @ it means the string will not actually contain the slashes. Alternatively you can double up on the slashes.

Upvotes: 4

Related Questions