Validation on TextBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VandanaMestri
    New Member
    • Mar 2010
    • 3

    Validation on TextBox

    hi,

    I am fresher in C# coding in .Net.

    i have been given a task of validation of 2 Text boxes.
    here is details : -
    we have a screen called Employee Qualification Details where Employee can update his Qualification Details.
    now for BE or Software Engineer Student, if they have any GPA, code is working however if there is Score we need to put a validation on "Out of" Text box which is optional.

    please help me to how to put validation on "Out of" Text Box when user enters any numerical value in "score" text box.

    Thanks in advance
    Vandy
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    A google search can typically turn up a lot of helpful information. For example, that's how I found this link :)



    You may also want to look into RegEx validation.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Or not use a textbox at all. Use a numericupdown with the min and max values within your range. No you don't have to validate because its not possible to enter in a bad value.

      Or do an "if...else" construct on the text.changed event, or on the textbox.exit event.

      There are lots of ways to handle this if you stop, consider and experiment a bit.

      Bytes has a policy regarding assisting students with their homework.

      The short version is that the volunteers here can't help you with schoolwork.
      A) We don't know what material you have and have not learned in class.
      B) We don't know the guidelines you must follow.
      C) In the long run giving you the answers actually short changes your education.

      Hint 1: Try hitting Google with terms of your programming language and primary terms of what you want to do. For example "C# custom events" or "VB datagrid Excel". I've found this to be a very effective tool.
      Hint 2: Your text book
      Hint 3: Your instructor
      Hint 4: Posting guidelines regarding homework assignments.

      Comment

      • VandanaMestri
        New Member
        • Mar 2010
        • 3

        #4
        Originally posted by VandanaMestri
        hi,

        I am fresher in C# coding in .Net.

        i have been given a task of validation of 2 Text boxes.
        here is details : -
        we have a screen called Employee Qualification Details where Employee can update his Qualification Details.
        now for BE or Software Engineer Student, if they have any GPA, code is working however if there is Score we need to put a validation on "Out of" Text box which is optional.

        please help me to how to put validation on "Out of" Text Box when user enters any numerical value in "score" text box.

        Thanks in advance
        Vandy
        hi,

        thanks for the help, have written the below code pls verify

        Validation - if Score Text box value entered is numeric, then out of also should be in numeric.

        Code:
        try
                {
                    //checks both textbox should be numerice if one box is numeric
                    int OutOf_Entered = int.Parse(txtOutOf.Text);
                    int Score_Entered = int.Parse(txtScore.Text);
                    //string score = string.Equals(txtScore.Text);
                    if (Score_Entered == OutOf_Entered)
                    {
                        errMessage.Append(CommonConstants.NEW_LINE + CommonConstants.OUT_OF_NUMERIC_VALIDATION);
                        flag = false;
                    }
        
                }
                catch (RaveHRException rex)
                {
                    LogErrorMessage(rex);
                }
                catch (Exception ex)
                {
                    // Supress you error message here
                }
        Last edited by tlhintoq; Mar 30 '10, 03:41 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

          Comment

          • VandanaMestri
            New Member
            • Mar 2010
            • 3

            #6
            thanks for your suggestion.

            Regards
            Vandana

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              If this is for a Windows Forms application, you might also like to look at the ErrorProvider component. I use it quite often. The flashing little red exclamations next to each field the user got wrong along with an explanation of why seems to work nicely for my user demographic.

              Provides a user interface for indicating that a control on a form has an error associated with it.

              Comment

              Working...