Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
I need an onkeydown function that limits the number of decimal places of that a html form can accept

For example, the html form should stop accepting decimal places after 0.1 so it wouldn't be possible to type in 0.01 to the html form box, thank for any help provided

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a regex to match values where there is only 1 decimal place. If the test fails, use Event.preventDefault:

input.addEventListener("keydown", function(e){
  if(!/^(\d+)?([.]?\d{0,1})?$/.test(this.value + e.key)){
    e.preventDefault()
  }
})
<input id="input">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!