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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:39:44+00:00 2026-05-25T20:39:44+00:00

I have input constraints on textbox that it will only accept the int and

  • 0

I have input constraints on textbox that it will only accept the int and until it can be parsed by Int64. The question is it clears out because he is assigning to String.Empty but what if its is not parsable by Int64 then i want to suppress that keypress. I tried adding code to keydown event that i have but it will also suppress the Int keys.

public static void SetInt64Input(Control tb)
    {
       tb.KeyDown += (sender, e) => {
        if (!IsIntKeyOrAlwaysAcceptableKey(e))
       //if not int key suppress it; Ex: A,B,.etc
            e.SuppressKeyPress = true;
       };
       tb.TextChanged += (s, e) => ClearAllNonInt64Inputs(tb);

    }

    private static void ClearAllNonInt64Inputs(Control tb)
    {
        long i;
        if (!Int64.TryParse(tb.Text, out i))
            tb.Text = String.Empty;
        else
            tb.Text =  Int64.Parse(tb.Text).ToString();
    }

i tried doing

 if(!Int64.TryParse(((TextBox)sender).Text,out junk)
    e.SuppressKeyPress = true;

but it dint work.

  • 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-25T20:39:44+00:00Added an answer on May 25, 2026 at 8:39 pm

    i am not sure whats the question.sorry.
    But if the input is not parsable due to its out of length of Int64 (more than 4 bytes), then i think restricting the numbers of characters in the Textbox may help. And if its not parsable due to a non-integer value, then use of IsNotDigit function will be helpfull in keypress event.

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

Sidebar

Related Questions

Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
We have some input data that sometimes appears with &nbsp characters on the end.
I have an input file that I want to sort based on timestamp which
I have an input field that is being set as a date picker. When
I have input fields, which I process with AJAX and send it on another
I have an arraylist set up. I have input instuctions set up too, so
I have saved input from a textarea element to a TEXT column in MySQL.
I have an input which at some points happens to have the focus. If
I have several input and option elements on my page, each (well almost) have

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.