title: Validating user input of decimal number
body: <p>I have a wpf text box and I want to check as the user inputs into it that they are only using 0 1 2 3 4 5 6 7 8 9 . [Decimal Point] characters for decimal numbers. I use this textbox to convert to a decimal later</p>
  
  <p>I am using the follow articles as a starting point 
  <a href="http://www.dotnetperls.com/regex-match" rel="nofollow noreferrer" title="regex match">Regex Match</a> <a href="http://wpf.2000things.com/tag/previewtextinput/" rel="nofollow noreferrer">Preview Text Input example</a> <a href="https://stackoverflow.com/questions/23388776/regex-to-allow-one-decimal-number-or-a-range-of-decimal-number">regex-to-allow-one-decimal-number-or-a-range-of-decimal-number</a></p>
  
  <p>Here is my xaml</p>
  
  <pre><code>&lt;TextBox Grid.Column="1" Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="tbTaxFreeLimit" Width="90" VerticalAlignment="Top" 
                                               AcceptsTab="True" 
                                               PreviewTextInput="tbDecimalCheck_PreviewTextInput"
                                              /&gt;
  </code></pre>
  
  <p>And c# </p>
  
  <pre><code>private void tbDecimalCheck_PreviewTextInput(object sender, TextCompositionEventArgs e)
  {
       // Test for decimal
       if (IsNumeric(e.Text)==false)
           e.Handled = true;
  }
  
  private bool IsNumeric(string s)
  {
      Regex r = new Regex(@"^[0-9]");
  
      return r.IsMatch(s);
  }
  </code></pre>
  
  <p>This example works fine for 0 1 2 3 4 5 6 7 8 9 but I can not enter the decimal point . </p>
  
  <p>If I change the to following code below it has no effect</p>
  
  <pre><code>Regex r = new Regex(@"^[0-9].");
  </code></pre>