I have one textbox in c# window forms that must allow only decimal numbers and minus sign. I need to write the code in textbox_textchanged event
Regards
Angela
I have one textbox in c# window forms that must allow only decimal numbers and minus sign. I need to write the code in textbox_textchanged event
Regards
Angela
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
VulpesRank #55 · 29.2K reputationPosted Apr 2, 2013, 7:35 AM EDT
The following should do that.
As well as removing invalid characters, it should also ensure that:
1. There's no more than one decimal point (only the last one entered is retained).
2. If there is a minus sign it's at the start of the string.
3. There's always at least one zero before a decimal point.