Why drag in all the overhead involved in a regular expression when a simpler method is available? Put this extension method in your code, and you can then iuse it on any string with any invalid character set:
public static class ExtendStrings
{
public static bool ContainsAny(this string value, string data)
{
bool result = false;
foreach(char c in data)
{
if (value.Contains(c)
{
result = true;
break;
}
}
return result;
}
}
Usage would be:
if (!myString.ContainsAny("(<,>,&,%,\",\\,/,?,*,|)"))
{
}