prevent writing all the letters except (the digits and (.))
What is the code to prevent writing all the letters except (the digits and (.)) Example 456.25
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Joginder BangerPosted Dec 26, 2014, 2:07 PM
In your question have no defined which application are used. I hope are understand what i say.
if you are working on web application you need the javascript or you are using the window application create the key_press event.
What you think about this code
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{ if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{ e.Handled = true; } // only allow one decimal point
if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
{ e.Handled = true; } }
lamasat lamasatPosted Dec 26, 2014, 10:08 PM