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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:38:23+00:00 2026-05-27T23:38:23+00:00

I have a small form where users enter a deposit in a dollar amount.

  • 0

I have a small form where users enter a deposit in a dollar amount. This amount can be positive or negative. I am attempting to validate the form each time a key is pressed to prevent letters or characters from being entered by accident.

Consider the function below:

var deposit = document.getElementById("deposit");

deposit.onkeyup = function() {
    var PATTERN = /\d$/;

    if (!deposit.value.match(PATTERN)) {
        deposit.value = deposit.value.replace(deposit.value.slice(-1), "");
    }
}

This works fine and dandy if you only want your user to be able to enter numbers. Any other character will simply be erased. Where I am having trouble is coming up with a pattern that will work on the fly to match a positive or negative currency (without the dollar sign). Users need to be able to enter an optional negative sign, at least one number, followed by a decimal point, followed by 2 more numbers.

Example deposit amounts:

0.09

100.45

4032.34

-0.90

-54.56

-1353.00

Any help coming up with a pattern, or perhaps even a better method, would be greatly appreciated. Please let me know if more detail is needed.

  • 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-27T23:38:24+00:00Added an answer on May 27, 2026 at 11:38 pm

    You can use this validation pattern to match those number values.

    ^-?\d+\.\d{2}$

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

Sidebar

Related Questions

I have a very small form where a user can enter their zip code
I have a form where users can enter multiple images to upload along with
In my c# application i have this small form which is used to set
I have a small web form that user will enter some patient data and
I have a classifieds website, and inside each classified, there is a small form.
i have made a small web application with form.html output.jsp ServletOne.java In the form.html,users
I have a small form inside a table. POSTing that form creates a new
I have a small contact form: <form method=post action=contact.php name=contactform id=contactform> <fieldset> <legend>Please fill
Hii , I have a small php form. I need it to come in
I want to globalize my application. I have created a small form which asks

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.