Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3671016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:26:08+00:00 2026-05-19T02:26:08+00:00

I am validating input on a form and attempting to prompt the user of

  • 0

I am validating input on a form and attempting to prompt the user of improper input(s) based on the combination of controls used.

For example, I have 2 combo boxes and 3 text boxes. The 2 combo boxes must always have a value other than the first (default) value, but one of three, or two of three, or all text boxes can be filled to make the form valid.

In one such scenario I have a 6 line if statement to try to make the test easily readable:

if ((!String.Equals(ComboBoxA.SelectedValue.ToString(), DEFAULT_COMBO_A_CHOICE.ToString())
    && !String.IsNullOrEmpty(TextBoxA.Text)
    && !String.Equals(ComboBoxB.SelectedValue.ToString(), DEFAULT_COMBO_B_CHOICE.ToString()))        
    ||
    (!String.IsNullOrEmpty(TextBoxB.Text)
    || !String.IsNullOrEmpty(TextBoxC.Text)))
{
    //Do Some Validation
}

I have 2 questions:

  1. Should this type of if statement be avoided at all cost?

  2. Would it be better to enclose this test in another method? (This would be a good choice as this validation will happen in more than one scenario)

Thanks for your input(s)!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:26:08+00:00Added an answer on May 19, 2026 at 2:26 am

    In such a case I find it helps to move some of the logic out of the if statement and into some more meaningfully named booleans. Eg.

    bool comboBoxASelected = !String.Equals(ComboBoxA.SelectedValue.ToString(), DEFAULT_COMBO_A_CHOICE.ToString());
    bool comboBSelected = !String.Equals(ComboBoxB.SelectedValue.ToString(), DEFAULT_COMBO_B_CHOICE.ToString());
    bool textBoxAHasContent = !String.IsNullOrEmpty(TextBoxA.Text);
    bool textBoxBHasContent = !String.IsNullOrEmpty(TextBoxB.Text);
    bool textBoxCHasContent = !String.IsNullOrEmpty(TextBoxC.Text);
    
    bool primaryInformationEntered = comboBoxASelected && textBoxAHasContent && comboBSelected;
    bool alternativeInformationEntered = textBoxBHasContent || textBoxCHasContent;
    
    if (primaryInformationEntered || alternativeInformationEntered)
    {
        //Do Some Validation
    }
    

    Obviously, name the combo and text boxes to reflect their actual content. When someone has to work their way through the logic several months down the line they’ll thank you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have 3 form input text for phone number. currently i am validating each
Where do you put user input validation in a web form application? View: JavaScript
assume i have a huge input form, which of course representing classes. i need
I really don't know advice with validating user input. I'm begining with RoR. I
I've got problems with setting focus to an input field after validating it. I've
In Model-View-Presenter pattern where should we write validations of user input.
I'm new to Spring, and I'm curious as to how to approach validating form
how do you prevent the entry of duplicate records in php mysql? validating input
My User model contains :name, :email, and :password fields. All 3 have validations for
I have a signup form on my home page which uses server side validation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.