Our application allows for user-defined "masks". Currently, if the user enters an invalid RegEx for the "mask", then when this value is used at runtime (setting the Mask property of the MaskedTextBox control), it generates an exception that (because it's done via Binding) is difficult to trap and handle gracefully.
I tried using using the .Net RegEx class to validate the expression, and I also tried using the RegEx in this URL
and while that catches some violations, there are others that are "valid" but still cause MaskedTextBox to error (for instance "[0-]").
Is there any way to determine that a given RegEx is valid for the MaskedTextBox control without having to do things on the UI thread?
I've determined that I can do this code
try
{
var text = new MaskedTextBox()
text.Mask = myMask;
return true;
}
catch
{
// Gracefully handle failure
return false;
}
but that requires me to do stuff on the UI thread, which interfers with my MVVM implementation (not to mention the fact that the library with the ViewModel doesn't draw a reference on any UI assemblies).
Is there a better way?
David Mullin
IMA Technologies