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 7590049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:18:38+00:00 2026-05-30T20:18:38+00:00

No matter what I enter my data is always true. Im taking the data

  • 0

No matter what I enter my data is always true. Im taking the data from a text box that the user can enter there data in. What am I doing wrong? Utility.ValidName and Utility.Email return true or false.

Check

string username = null;
string email = null;

username = textBox1.Text;
email = textBox2.Text;

bool vusernam = false;
bool vemail = false;

vusernam = Utility.ValidName ( username );
vemail = Utility.ValidEmail ( email );

if ( vusernam == true && vemail == true )
{
    Utility.WelcomeMessage ( string.Format ( "Hello {0}\nEMail: {1}\nWelcome!" , username , email ) );
    secondForm.Show ( );
    this.Hide ( );
}
else
{
    MessageBox.Show ( "Please Enter a Username and Email Adress!" );
}

Valid Username and Email

 public static bool ValidEmail ( string email )
    {
        string strTest = email;
        Regex pattern = new Regex ( @"(?<name>\S+)@(?<domain>\S+)" );
        Match match = pattern.Match ( strTest );

        if ( String.IsNullOrEmpty ( email ) || !match.Success )
        {
            Console.Write ( "\nInvalid Email!" );
        }
        return true;
    }

    public static bool ValidName ( string name )
    {
        string strTest = name;


        if ( String.IsNullOrEmpty ( name ) )
        {


            Console.Write ( "\nInvalid Name!" );


        }
        return true;
    }
  • 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-30T20:18:39+00:00Added an answer on May 30, 2026 at 8:18 pm

    You always return true, no matter what.

    Add a return false after your Console.Write. Simply outputting an error message doesn’t cause your validation to fail.

    public static bool ValidName ( string name )
    {
        string strTest = name;
    
        if ( String.IsNullOrEmpty ( name ) )
        {
            Console.Write ( "\nInvalid Name!" );
            return false;
        }
        return true;
    }
    

    Side notes:

    if ( vusernam == true && vemail == true )
    

    can be reduced to simply

    if(vusernam && vemail)
    

    and string strTest = name; appears to serve no purpose at all.

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

Sidebar

Related Questions

I have a pagination functionality, where the user can either enter page number OR
No matter how you scroll, the div should always be at the bottom of
Does it matter to developers that the current, and newer versions of .Net don't
This may be a matter of style, but there's a bit of a divide
The big problem lies in the fact that the code, no matter which number
The user will enter a customer number, then select a file to upload, then
Maybe it's something I'm doing wrong. I'm just learning Linq because I'm bored. And
Using Delphi 7 I am reading from a serial port. The read is always
I'm trying to write an app that can login to SSH with a password,
I have a DGV that has its datasource set to a BindingList. There is

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.