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

Add a preview text input event. Like so: <TextBox PreviewTextInput=”PreviewTextInput” />. 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 … Read more