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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:33:30+00:00 2026-06-14T07:33:30+00:00

I used from Error Provider in C# winform. in my form have textbox. error

  • 0

I used from Error Provider in C# winform. in my form have textbox. error provider checked it that it contain two number. it means that input is digit and number of digit is two number. when input is 2 char , error provider is worked but when input is char and digit, error provider didn’t worked.
please check my code.

 private void textbox1_Leave(object sender, EventArgs e)
        {
            string text = textbox1.Text;
            bool hasDigit = false;

                foreach (char letter in text)
                {
                    if (char.IsDigit(letter))
                    {
                        hasDigit = true;
                        break;
                    }
                }

            // Call SetError or Clear on the ErrorProvider.
            if (!hasDigit )
            {
                errorProvider1.SetError(textbox1, "Please enter digit");
            }
            else if(hasDigit) 

            {

                if (text.TextLength != 2)
                {
                    errorProvider1.SetError(textbox1, "Number of digit is two number");
                }
                else
                errorProvider1.Clear();
            }
        }
  • 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-14T07:33:31+00:00Added an answer on June 14, 2026 at 7:33 am

    So you want to ensure that all chars are digits. But you’re checking only the first, if that’s a digit you’re breaking the loop:

    foreach (char letter in text)
    {
        if (char.IsDigit(letter))
        {
            hasDigit = true;
            break;
        }
    }
    

    Instead you could use Linq for this. Enumerable.All is made for this purpose:

    bool allDigits = text.All(c => Char.IsDigit(c));
    

    (but maybe i’m totally off the track since the question is not so clear imho)

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

Sidebar

Related Questions

I tweaked this script that I used from JqueryUi and I have a problem.
I have used FlipView from Metro Applications and that's what I'm trying to looking
I have a form that will not open in the designer. I used the
I have a tooltip being used on hover from a tr. I am using
I am working on a host that blocks my .htaccess file from being used
The error: OLE DB provider 'Microsoft.ACE.OLEDB.12.0' cannot be used for distributed queries because the
I have made a winform app where i have used vectors of array[n][n] type
I have two applications which use the same content provider, but I can't put
I have a website set up that uses a custom 404 error page. This
I have setup a custom provider to allow setting validation attributes from a data

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.