3,034 questions
Hi @VoyTec ,
This question is similar to your previous question, you just need to modify the regular expression ^[\\s\\d\\s]*$
.
Page.xaml
<TextBox TextChanged="TextBox_TextChanged" />
Page.xaml.cs
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var textbox = (TextBox)sender;
if (!Regex.IsMatch(textbox.Text, "^[\\s\\d\\s]*$") && textbox.Text != "")
{
int txtPos = textbox.SelectionStart - 1;
textbox.Text = textbox.Text.Remove(txtPos, 1);
textbox.SelectionStart = txtPos;
}
}
Thank you
Junjie