I'm developing an application in .NET where the user can provide Regular Expressions that are afterwards used to validate input data.
I need a way to know if a regular expression is actually valid for the .net regex engine.
Thanks for any help
I'm developing an application in .NET where the user can provide Regular Expressions that are afterwards used to validate input data.
I need a way to know if a regular expression is actually valid for the .net regex engine.
Thanks for any help
Just try to compile the given regex. You can do that by creating the Regex object and passing the pattern to it. Here's a sample code:
public static bool IsRegexPatternValid(String pattern)
{
try
{
new Regex(pattern);
return true;
}
catch { }
return false;
}