private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = System.Text.RegularExpressions.Regex.IsMatch(e.Text, @"[0-9]+"); base.OnPreviewTextInput(e); }