Code for TextBox accept only numeric value with only one '.'

Code for TextBox accept only numeric value with only one '.'

private void textvalidate(TextBox textbox, KeyPressEventArgs e)

        {

            bool IsNumeric = false;

            string Text = textbox.Text;

            if (e.KeyChar == '\b')

            {

                e.Handled = false;

            }

            else

            {

                if (!char.IsDigit(e.KeyChar))

                {

                    e.Handled = true;

                }

                else

                {

                    e.Handled = false;

                    IsNumeric = true;

                }

                if (!IsNumeric)

                {

                    if (e.KeyChar.ToString() == ".")

                    {

                        if (Text.IndexOf('.') == -1)

                        {

                            e.Handled = false;

                        }

                    }

                }

            }

        }

Ebook Download
View all
Learn
View all