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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:07:51+00:00 2026-06-06T00:07:51+00:00

I’m trying to validate an ID. I have this class called ManejadorTickets in which

  • 0

I’m trying to validate an ID.

I have this class called ManejadorTickets in which -among others things- I call the method to validate an ID (the ID is the Cedula is something like SSN in USA).

    public void venderTicket ()
    {
        // more code...

        Console.Write("\nCedula: ");
        string cedula = Validador.validarCedula(Console.ReadLine().Trim());

        // more code...
    }

This is my validarCedula method in Validador class.

public static String validarCedula (string cedula)
        {
            // Limpiar la entrada de caracteres extraños
            cedula = cedula.Replace("-", "");
            cedula = cedula.Replace(" ", "");

            // Debe tener 11 caracteres
            if (cedula.Length != 11)
            {
                Impresor.imprimirOpExitosa(cedula.Length.ToString());
                Impresor.imprimirError("La cedula debe tener 11 digitos", "Cedula: ");
                validarCedula(Console.ReadLine().Trim());
            }

            // Todos los caracteres deben ser numeros
            char[] arrayLetras = cedula.ToCharArray();
            foreach (char c in arrayLetras)
            {
                if (NUMEROS.IndexOf(c) == -1)
                {
                    Impresor.imprimirError("Todos los caracteres deben ser numericos." +
                                            " Los guiones o espacios no se toman en cuenta.", "Cedula: ");
                    validarCedula(Console.ReadLine().Trim());

                }
            }

            return cedula;
        }

The method above eliminate hyphens and space from the input. Is also check if the input has exactly 11 characters and if all characters are numbers.

Note: NUMBERS is a constant I declared at the beginning of the class
private const string NUMEROS = "0123456789";

But when I running the program, enter a wrong value as a Cedula (to test my validation method) such as “foo”, it happens what should happens (ask for the value again). So far so good, now when I type a correct value such as 00114905656 (all numbers and 11 digits) it ask again for a value and that should not happen because the last entered value was correct.

I tried debugging my applications and I see that the method execute as it should, but when the compiler execute the statement return cedula; (last sentence in the method) it jumps to the first validarCedula(Console.ReadLine().Trim()); statement that’s the one inside the if (cedula.Length != 11) statement. And I don’t understand WHY that happens. When the return is executed the method is supposed to finish.

  • 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-06-06T00:07:51+00:00Added an answer on June 6, 2026 at 12:07 am

    You are calling validarCedula from within itself. This is called recursion.

    Try stepping through from the beginning. Look at the call-stack window.

    I think you need to restructure your program a bit.

    Try implementing validarCedula more like this:

    static bool validarCedula(string cedula) {
       // do your string replace here
       // if it's ok, return true
       // if it's bad, return false.  
       // do not call validarCedula from here!      
    }
    

    And then do this in your vendorTicket function, so you still get it to re-prompt until it passes:

    string cedula;
    bool ok = false;
    while (!ok) {
        Console.Write("\nCedula: ");
        cedula = Console.ReadLine().Trim();
        ok = validarCedula(cedula);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has

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.