textbox validation for allow one “ . ” value c#

后端 未结 8 1613
悲&欢浪女
悲&欢浪女 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:50

    if(e.KeyChar.Equals('\b'))
     {
      e.Handled = false;
     }
    else
     if (!char.IsControl(e.KeyChar)
               && !char.IsDigit(e.KeyChar)
               && e.KeyChar != '.')
      {
            e.Handled = true;
      }
     else
        // only allow one decimal point
        if (e.KeyChar == '.'
            && textBox1.Text.IndexOf('.') > -1)
      {        
        e.Handled = true;  
      }
    

提交回复
热议问题