Hello,
I have a desktop application that uses this ([PM+-]\d{1,5}(\.\d{1,2})*)* RegEx as mask, how can I do that in MaskedTextBox? This RegEx allows me to input in my textbox as follows:
+5+3+2+1.5
or P20
or M15
Thanks.
Hi Glenn,
You can add a handler for the “Validating” event of the Masked Textbox and add a System.Text.RegularExpressions reference in your code. Here is an example with C# code you can use as a model:
private void maskedTextBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
// Define a regular expression for repeated words.
Regex rx = new Regex(@”([PM+-]\d{1,5}(\.\d{1,2})*)*”,
RegexOptions.Compiled | RegexOptions.IgnoreCase);
// Define a test string.
string text = maskedTextBox1.Text;
// Find matches.
MatchCollection matches = rx.Matches(text);
// Report on each match.
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
AlertBox.Show(match.Value);
}
}
Please let me know if this works for you!
Best regards,
Levie
Please login first to submit.