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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:39:31+00:00 2026-06-02T18:39:31+00:00

I want to check the number format as the user types in each number

  • 0

I want to check the number format as the user types in each number in the following format
Three digits before decimal and one digit after point(if any)

The moment the user enters the 3 digits, Im trying to add decimal point. Is there any event which is fired when user enters a number?

The TextInput and TextInputStart events do not work as expected. When i try to enter 332 it shows as 233. The following function is called on the TextInputStart event.

private void TestFunction(object sender, TextCompositionEventArgs e)
    {
        TextBox txtbox = e.OriginalSource as TextBox;
        string r = txtbox.Text;

        if(r.Contains('.'))
        {
            for (int i = 0; i < r.Length; i++)
            {
                if (r.Substring(i, 1) == ".")
                {
                    txtbox.Text = r.Substring(0, i + 2);

                }
            }
        }

        if (r.Length == 2 && r[2] != '.')
        {
            r += ".";
            txtbox.Text = r;
        }

    }

While debuggin i noticed that, TextInputStart is fired and the text box has the previous string and not the last entered string.

Any way out? 🙁

  • 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-02T18:39:35+00:00Added an answer on June 2, 2026 at 6:39 pm

    I used regular expressions to check 3 digits before decimal and one digit after decimal. The following function is called on the key up event of the textbox. Saves a lot of time and can avoid the unnecessary use of messagebox. If anybody is looking out for an answer, here is mine.

     private void ValidateValue(object sender, KeyEventArgs e)
        {
            string sInput, sPattern;
    
            TextBox txtbox = e.OriginalSource as TextBox;
            sInput = txtbox.Text;
    
            sPattern = @"^([0-9]{0,3})?(\.([0-9]{1})?)?$";
            Regex reg = new Regex(sPattern);
    
    
            if (reg.IsMatch(sInput))
            {
                if (sInput != "" && (sInput[0] == '.' || sInput[0] == '0'))
                {
                    txtbox.Text = "";
                    return;
                }
    
                txtbox.Text = sInput;
            }
            else
            {
                txtbox.Text = sInput.Substring(0, sInput.Length - 1);
                txtbox.Select(txtbox.Text.Length, 0);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check if user input a positive integer number. 1 = true
I want to take in a certain format of one text file. After the
A large number of clients want to check in with a server about once
i want a way to check if the number has comma, then it return
In my website I want to virus-check any uploaded files before saving them into
So I want to use an XSL to format a date before its sent
I want to check if string doesn't have more than 5 numbers. I can
I have a bunch of numbers timestamps that I want to check against a
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly

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.