How do I get a TextBox to only accept numeric input in WPF?

Add a preview text input event. Like so: . Then inside that set the e.Handled if the text isn’t allowed. e.Handled = !IsTextAllowed(e.Text); I use a simple regex in IsTextAllowed method to see if I should allow what they’ve typed. In my case I only want to allow numbers, dots and dashes. private static readonly Regex _regex = new Regex(“[^0-9 …

Read More