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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:31:01+00:00 2026-05-28T06:31:01+00:00

I am confused about strings and int. and can’t validate a name to be

  • 0

I am confused about strings and int. and can’t validate a name to be without numbers and strange charchters. a-z and A-Z are fine. I understand the do while loop and use of a sentinel. I seen Regex on here but it doesn’t work in my code for some reason unknown to me. I would rather go with a simple solution that I can understand it. I have validation of int in my code working great, but validating the name gets bool, and int errors.

    static void Main(string[] args)
    {
        int age;
        double mileage;
        string strInput, name;
        bool isValid;

        DisplayApplicationInformation();

        DisplayDivider("Start Program");
        Console.WriteLine();

        DisplayDivider("Get Name");
        strInput = GetInput("your name");
        name = strInput;
        Console.WriteLine("Your name is: " + name);
        Console.WriteLine();

        do
        {
        DisplayDivider("Get Age");
        strInput = GetInput("your age");
        isValid = int.TryParse(strInput, out age);
        if (!isValid || (age <= 0))
        {
            isValid = false;
            Console.WriteLine("'" + strInput + "' is not a valid age entry. Please retry...");
        }
        }while (!isValid);
        Console.WriteLine("Your age is: " + age);
        //age = int.Parse(strInput);
        //Console.WriteLine("Your age is: " + age);
        Console.WriteLine();

        do
        {
        DisplayDivider("Get Mileage");
        strInput = GetInput("gas mileage");
        isValid = double.TryParse(strInput, out mileage);
        if (!isValid || (mileage <= 0))
        {
            isValid = false;
            Console.WriteLine("'" + strInput + "' is not a valid mileage entry. Please retry...");
        }
        } while (!isValid);
        Console.WriteLine("Your age is: " + mileage);
        //mileage = double.Parse(strInput);
        //Console.WriteLine("Your car MPT is: " + mileage);

        TerminateApplication();
    }
  • 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-28T06:31:01+00:00Added an answer on May 28, 2026 at 6:31 am

    Here is a Regex that works for what you want

            Regex reg = new Regex("^[A-Za-z]+$");
            do
            {
                DisplayDivider("Get Name");
                strInput = GetInput("your Name");
                isValid = reg.IsMatch(strInput);
                if (!isValid)
                {
                    isValid = false;
                    Console.WriteLine("'" + strInput + "' is not a valid name entry. Please retry...");
                }
            } while (!isValid); 
    

    Basically, it says, “Match start of the string (^ means start) and only letter till end of string ($ means end of string) and there must be 1 or more letters (that’s the +)”

    Probably the easiest

    Now, this is assuming of course that you don’t want “Firstname Lastname” because that would mean there is a space involved. Let me know if you need spaces for name separations.

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

Sidebar

Related Questions

I'm a little confused about C strings and wide C strings. For the sake
I am confused about which is which. Can someone explain the difference between the
I've been staring at this for a while now and I'm confused about what
I've been confused over the past weeks now about events. I understand how delegates
I am always confused about return a string literal or a string from a
I am a little confused about Accept-Encoding . I have Web Service which would
I am a little confused about the roles of a java application server and
I'm a bit confused about the size of my App! The folder and all
I am a bit confused about the 'rules' of when a TextView element displays
I'm a little confused about something. I wrote an app and tested it on

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.