Howdy, Stranger!

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


validating a textBox in winform with C++

LordYTLordYT Member Posts: 16
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.


  • WEBMASTERWEBMASTER Member Posts: 549
    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
  • LordYTLordYT Member Posts: 16
    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...
  • LordYTLordYT Member Posts: 16
    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.