title: How to disallow white space in this regular expression?
body: <pre><code>Dim regex = New Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$")
  e.Handled = Not regex.IsMatch(TryCast(sender, TextBox).Text.Insert(TryCast(sender, TextBox).SelectionStart, e.Text))
  </code></pre>
  
  <p>With this code, I am able to accept only decimal inputs for the textbox. But user is still able to enter white space to the textbox. How do I disallow that? I have tried adding in <code>\s</code> as the white space character but no luck.</p>
  
  <p><strong>UPDATE</strong>
  Tried using this regex as suggested as well. But still able to enter white space into the textbox. Here is the code</p>
  
  <pre><code>Private Sub textBox4_PreviewTextInput(sender As Object, e As TextCompositionEventArgs) Handles textBox4.PreviewTextInput
      'Dim regex = New Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$") //This is the original code.
      Dim regex = New Regex("^\d*(\.\d*)?$")
      e.Handled = Not regex.IsMatch(TryCast(sender, TextBox).Text.Insert(TryCast(sender, TextBox).SelectionStart, e.Text))
  End Sub
  </code></pre>
  
  <p>Also, there is no KeyPress event for textbox in Wpf..</p>