I tried to add regex to TextBox in xaml but after i added it, it doesn't work, can't enter any value. I wanted only value from below to by entered to my textbox. Tried my regex on online test and it works https://regex101.com/r/OtGvt7/1 but it doesnt work in my app.
123-456
23-234
private void Test1(object sender, TextCompositionEventArgs e)
{
if (!Regex.IsMatch((e.Source as TextBox)?.Text + e.Text, "^[0-9]{0,3}(?=-)[0-9-]{0,4}$"))
{
e.Handled = true;
}
}
My second regex works only if i enter 'x' first, it works online https://regex101.com/r/m2ehFK/1
if (!Regex.IsMatch((e.Source as TextBox)?.Text + e.Text, "^[0-9,][x][0-9,]{0,6}$"))
{
e.Handled = true;
}
but my goal was to achieve something like this
1x21
2,2x1
3,3x1,2
33x1,1