CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: form validation

  1. #1
    Join Date
    May 2002
    Posts
    121

    form validation

    Hi,

    I have a set of text boxes and I want to test for the type of the input, whether it's a string, decimal or integer.

    If any of those do not match I want to display an error message.

    How to check the strings in text boxes if they satisfy the format?

    How to display an alert window?

    Thank you for your help!

  2. #2
    Join Date
    Jul 2001
    Location
    Romania
    Posts
    52

    alert windows

    1) There is a MessageBox Class in .net which provide you an alert window as customisable as you want.

    ex.
    MessageBox.Show("You must enter a name.", "Name Entry Error",
    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

    Check the sdk documentation for mor information...

    2) There is a Type Class in .net which provide you all the method you need to get a type to check a type...

    GetType method..

    Check the sdk documentation for mor information...
    It is the weak who are cruel,
    only the strong can be truly gentle!
    Szilard

  3. #3
    Join Date
    May 2002
    Posts
    121
    The problem with get type is that input to text boxes are strings.

  4. #4
    Join Date
    Feb 2002
    Location
    Spain
    Posts
    148
    Hi:

    For doing validation stuff you may include the System.Text.RegularExpression namespace to your project and use the classes on it.

    Take a look at http://windows.oreilly.com/news/csharp_0101.html.

    You may also take a look at http://regexlib.com/Default.aspx., you will find there a lot of regular expressions.

    VictorL

  5. #5
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265
    You could always just try converting them to your desired format:
    Code:
    try
    {
       myDecimal = Decimal.Parse( myTextBox.Text );
    }
    catch( FormatException ex )
    {
       MessageBox.Show( "You entered a bad number,  stupid!", "Bleh!" );
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured