private void Testbox_TextChanged(object sender, TextChangedEventArgs e)
{
var textbox = (TextBox)sender;
if (!Regex.IsMatch(textbox.Text, "^\\d*\\.?\\d*$") && textbox.Text != "")
{
int pos = textbox.SelectionStart - 1;
textbox.Text = textbox.Text.Remove(pos, 1);
textbox.SelectionStart = pos;
}
}
只能输入字符和数组的正则表达式:"^[A-Za-z0-9]+$"