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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:35:29+00:00 2026-05-27T19:35:29+00:00

How do I get an input field (text) to accept only numbers and to

  • 0

How do I get an input field (text) to accept only numbers and to automatically format it to two decimal places, as the user is typing in each digit?

For example, the default value of the field is 0.00
User wants to enter 23.50

Step 1: user types 2 - field shows 0.02
Step 2: user types 3 - field shows 0.23
Step 3: user types 5 - field shows 2.35
Step 4: user types 0 - field shows 23.50

Thanks in advance!

  • 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-27T19:35:29+00:00Added an answer on May 27, 2026 at 7:35 pm

    the following regex expression matches 99.99, 99999.99, etc.

    \$\d+\.\d{2}
    

    use jQuery’s .live() function to wire the keyup event to your text box.

    $('.textBoxDecimalOnly').live('keyup', function () {
        // inside this keyup hook, grab the value in the text box.
        // if it matches the regex... do something
        // else do something different
    });
    

    when keyup happens, check the value of the text box against that regex expression and do what you wish with your answer.

    to make it work from right to left you could reformat the string…

    // 1. get text in the box.
    // 2. if length < 3 ... append a "." to the first string.
    // 3. if > 3 get the index of the 2nd to last character and append "." just before it.
    

    stuff that logic inside your live hook.

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

Sidebar

Related Questions

I'd like to show the keyboard and get user input without a text field.
So, on my form I have two input methods, a text field and a
I am trying to get the value of the text in the input fields.
Is there a way to get an <input /> -field in HTML to wrap
I want to get user input in one page, store that in a php
I am trying to get text input from the keyboard in Java 6. I
What's the best way to get user input in a C program where the
I've got a date text field I wish to only sometimes attach a DatePicker
I'm building a text input field specialized for entering and editing times. One of
I have a simple input field : <input type=text id=someid name=somename class=someclass> I'm trying

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.