title: Silverlight textbox to accept only decimals
body: <p>I have a Silverlight app with a textbox whose input I want to limit to decimal numbers only. Searching the web I came across the following possible solution (curiously in different places with different people claiming authorship of the same lines of code) 
  It appears to work well except that after at least 1 numeral has been entered it will then allow the letter 'd' in either upper or lower case to be entered, I can't figure out why that is and thus can't figure out how to prevent that from happening. Could anyone please provide a solution. Many thanks.</p>
  
  <pre><code>    private void Unit_KeyDown(object sender, KeyEventArgs e)
      {
  
          if (e.Key == Key.Tab)
          {
  
          }
          var thisKeyStr = "";
          if (e.PlatformKeyCode == 190 || e.PlatformKeyCode == 110)
          {
              thisKeyStr = ".";
          }
          else
          {
              thisKeyStr = e.Key.ToString().Replace("D", "").Replace("NumPad", "");
          }
          var s = (sender as TextBox).Text + thisKeyStr;
          var rStr = "^[0-9]+[.]?[0-9]*$";
          var r = new Regex(rStr, RegexOptions.IgnoreCase);
          e.Handled = !r.IsMatch(s);
  
      }
  </code></pre>