In our WPF application, we need to restrict a TextBox to only allow to enter number from 5 to 9999.
In WPF, we could implement the following to only allow the number input
in XAML, define TextBox's PreviewTextInput = "NumericOnly"
private void NumericOnly(object sender, TextCompositionEventArgs e) { e.Handled = Utility.IsTextNumeric(e.Text); }
public static bool IsTextNumeric(string str) { Regex reg = new Regex("[^0-9]"); return reg.IsMatch(str); }To only 9999, we can set TextBox MaxLength = "4".
We know we could use validation input value to achieve the goal.
Is there a easy way to only allow number from 5 to 9999 by TextBox? Thx!
JaneC