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

  • Home
  • SEARCH
  • 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 6146579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:58:12+00:00 2026-05-23T18:58:12+00:00

I am trying to disable all keystrokes entered into a text box except the

  • 0

I am trying to disable all keystrokes entered into a text box except the following:

0 1 2 3 4 5 6 7 8 9 . (so all keys except the numbers and the ‘.’ should be disabled)

Right now I have the following code but it only checks to see if a letter was entered as the first value (not to mention its really sloppy):

    private void yDisplacementTextBox_TextChanged(object sender, EventArgs e)
    {
         if (yDisplacementTextBox.Text.ToUpper() == "A" || yDisplacementTextBox.Text.ToUpper() == "B" || yDisplacementTextBox.Text.ToUpper() == "C" ||
             yDisplacementTextBox.Text.ToUpper() == "D" || yDisplacementTextBox.Text.ToUpper() == "E" || yDisplacementTextBox.Text.ToUpper() == "F" || 
             yDisplacementTextBox.Text.ToUpper() == "G" || yDisplacementTextBox.Text.ToUpper() == "H" || yDisplacementTextBox.Text.ToUpper() == "I" ||
             yDisplacementTextBox.Text.ToUpper() == "J" || yDisplacementTextBox.Text.ToUpper() == "K" || yDisplacementTextBox.Text.ToUpper() == "L" ||
             yDisplacementTextBox.Text.ToUpper() == "M" || yDisplacementTextBox.Text.ToUpper() == "N" || yDisplacementTextBox.Text.ToUpper() == "O" ||
             yDisplacementTextBox.Text.ToUpper() == "P" || yDisplacementTextBox.Text.ToUpper() == "Q" || yDisplacementTextBox.Text.ToUpper() == "R" ||
             yDisplacementTextBox.Text.ToUpper() == "S" || yDisplacementTextBox.Text.ToUpper() == "T" || yDisplacementTextBox.Text.ToUpper() == "U" ||
             yDisplacementTextBox.Text.ToUpper() == "V" || yDisplacementTextBox.Text.ToUpper() == "W" || yDisplacementTextBox.Text.ToUpper() == "X" ||
             yDisplacementTextBox.Text.ToUpper() == "Y" || yDisplacementTextBox.Text.ToUpper() == "Z")
        {
            MessageBox.Show("Please enter a numeric value for the Y Displacement.", "Y Displacement: Numbers Only Error",
                       MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }

Is there anyway to have it so when pressed, all of the keys on the keyboard (except the numbers and the period button) do not register (or disables) the actual value of the key and inputs nothing?

  • 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-23T18:58:12+00:00Added an answer on May 23, 2026 at 6:58 pm

    Use textBox1.KeyPress += textBox1_KeyPress

    This code only allowing numbers and . and the backspace.

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar > (char)Keys.D9 || e.KeyChar < (char)Keys.D0) && e.KeyChar != (char)Keys.Back && e.KeyChar != '.')
        { 
            e.Handled = true; 
        }
        //Edit: Alternative
        if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)Keys.Back && e.KeyChar != '.')
        {
            e.Handled = true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery UI and trying to disable all text boxes in a
Trying to make a MySQL-based application support MS SQL, I ran into the following
I am trying to bulk disable all the submit buttons present in my form.
I'm trying to enable or disable all the control in a window as the
I'm trying to disable a bunch of controls with JavaScript (so that they post
I'm trying to disable a label control from the CheckedChanged event handler of a
I am trying to find a way to disable Design / Split views from
I am trying to set the disabled font characteristics for a Label Control. I
Trying to keep all the presentation stuff in the xhtml on this project and
Trying to find where to disable individual keyboard shortcuts in the jQuery version of

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.