Search code examples
winformstextbox

WinForm Textbox with decimal number validation


How do you check if a user put a dot or comma in the textbox in my decimal number input, and how do I get the message that the error is in the lab if the input is incorrect when using a WinForm?


Solution

  • You haven't stated which language you are using. Is this what you're looking for?

    c#

    if (textBox1.Text.Contains(".") || textBox1.Text.Contains(","))
       {
           MyLabel1.Text = "Textbox Contains . or ,";
       }
    

    You can just change the "MyLabel1.Text" to whatever your Label is called.