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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:13:55+00:00 2026-06-17T16:13:55+00:00

I am trying to figure out how to make it so that if I

  • 0

I am trying to figure out how to make it so that if I press my button to do a action, (like show a messagebox) and my maskedtextbox’s text isn’t a number, then it goes and does something like say that you can only have a number in the TextBox or something like that. I can’t seem to figure it out.

I have tried to use this:

if (!System.Text.RegularExpressions.Regex.IsMatch(binTxtbx.Text, @"0-9"))
            e.Handled = true;

But if I use that it wont put any text into the maskedtextbox.

If you know if anyone asked the same question that I did, please tell me.

  • 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-17T16:13:56+00:00Added an answer on June 17, 2026 at 4:13 pm

    If you don’t mind using a maskedTextBox, and just don’t like the underscores (as you mentioned in your comment), simply change the PromptChar to a blank.

    You can do this either in the Design View in the MaskedTextBox Properties, or in the code like this:

    myMaskedTextBox.PromptChar = ' ';
    

    EDIT:

    Alternatively, (if you don’t want to use a maskedTextBox) you could wire the KeyDown event to an EventHandler like this:

        private void numericComboBox_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                e.SuppressKeyPress = false;
    
                // Determine whether the keystroke is a number from the top of the keyboard.
                if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
                {
                    // Determine whether the keystroke is a number from the keypad.
                    if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                    {
                        // Determine whether the keystroke is a backspace or arrow key
                        if ((e.KeyCode != Keys.Back) && (e.KeyCode != Keys.Up) && (e.KeyCode != Keys.Right) && (e.KeyCode != Keys.Down) && (e.KeyCode != Keys.Left))
                        {
                            // A non-numerical keystroke was pressed.
                            // Set the flag to true and evaluate in KeyPress event.
                            e.SuppressKeyPress = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Handle any exception here...
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to make it so that when I'm moving
I'm trying to figure out if I have points that make for example a
I am trying to figure out how to make it that when my timer
I'm trying to figure out how make a basic GET request using Network.HTTP.simpleHTTP that
I'm trying to figure out how to make a scope that will return random
I'm trying to make a regular button that functions like a toggle button, but
I am trying to figure out how to make my layout have the following
I'm trying to figure out how to make jQuery slide #content2 down and replace
I'm trying to figure out a way to make demos for a program I've
I've been trying to figure out how I can make a query with MySQL

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.