validating a textBox in winform with C++

Can someone help me with a validating from a double in a textbox. My problem is to be sure that the user don't whrite 2 virgule in that textBox. I resolve the numeric problem with a "keypress" event:
[color=Blue] if ( !(Char::IsDigit( e->KeyChar ) || e->KeyChar == '.' || e->KeyChar == (char)(Keys::Back)) )
e->Handled = true;
Thanks a lot, every idea is welcome.


  • Perhaps use a regular expression to validate, that is often the easiest way to validate complex input.

    Tore Nestenius
    [blue][italic][b]/WEBMASTER[/b][/italic][/blue] Programmers Heaven
  • Thanks a lot, I just order a book "The C++ Standard Library Extensions" to learn a bit more about regular expressions. It doesn't look so easy but I will work on it...
  • I need to enter 1 to 3 digits in that textBox and if necessary a comma. Here is the code I used but it doesn't match. You can enter 2 or more comma I don't want that.
    Regex^ rx = gcnew Regex( "^-?\d+(\.\d{2})?$" );
    Do you have any idea how I can solve this ?
    Thanks a lot
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!