textbox validation for allow one “ . ” value c#

后端 未结 8 1618
悲&欢浪女
悲&欢浪女 2021-01-23 08:56

I want textbox validation for allowing only one . value and only numbers. Means my textbox value should take only numerics and one . value. Value shoul

8条回答
  •  悲&欢浪女
    2021-01-23 09:51

    Another example ,

     private void txtPrice_KeyPress(object sender, KeyPressEventArgs e)
        {
             // To disallow typing in the beginning writing
            if (txtPrice.Text.Length == 0)
            {
                if (e.KeyChar == '.')
                {
                    e.Handled = true;
                }
            }
            if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8 && e.KeyChar != 46)
            {
                e.Handled = true;
            }
            if (e.KeyChar == '.' && txtPrice.Text.IndexOf('.') > -1)
            {
                e.Handled = true;
            }
        }
    

提交回复
热议问题