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
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Joginder BangerRank #360 · 7K reputationPosted Dec 26, 2014, 9:07 AM EST
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 lamasat55 reputationPosted Dec 26, 2014, 5:08 PM EST