Hi Techies,
I am making a windows form.
I am trying to validate a text box to accept only float value. Below is the code, where txtPurchasePrice is my textBox. The code below works fine:-
private void txtPurchasePrice_TextChanged(object sender, EventArgs e) { txtPurchasePrice.KeyPress += new KeyPressEventHandler(rtbQuantity_KeyPress); } private void rtbQuantity_KeyPress(object sender, KeyPressEventArgs e) { ////if ((e.KeyChar >= '0') || (e.KeyChar <= '9')) //// e.Handled = true; if (!char.IsNumber(e.KeyChar) & (Keys)e.KeyChar != Keys.Back & e.KeyChar != '.') { e.Handled = true; } base.OnKeyPress(e); }
Problem: It accepts only first letter as alphabet, rest is OK. (means not working on first entered letter)