How to allow, and limit to one "." (period) character in a TextBox? (C# winforms)
<p>I have this code from MSDN that allows only numeric characters into a TextBox.
But I can't modify it to accept a "." as an input and limit to one. </p>

<pre><code>Ex: 12.50     valid!
    236.3247  valid!  
    2..5      invalid
    //other non-numeric input invalid
</code></pre>

<p>Considering the code below:</p>

<pre><code>private bool nonNumberEntered = false;

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    nonNumberEntered = false;

    if (e.KeyCode &lt; Keys.D0 || e.KeyCode &gt; Keys.D9)
    {
        if (e.KeyCode &lt; Keys.NumPad0 || e.KeyCode &gt; Keys.NumPad9)
        {
            if (e.KeyCode != Keys.Back)
            {
                nonNumberEntered = true;
            }
        }
    }
    if (Control.ModifierKeys == Keys.Shift)
    {
        nonNumberEntered = true;
    }
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (nonNumberEntered == true)
    {
        e.Handled = true;
    }
}
</code></pre>

<p>Kindly post your modified code. Thanks a lot.</p>
