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

134
Views
Evite insertar un valor mayor que el máximo al mismo tiempo restringir a decimal

Quiero restringir la entrada del usuario a dos decimales solo al mismo tiempo restringir la entrada del usuario no mayor que el valor máximo. Mi código a continuación no funciona en conjunto.

Código JS

 var validate = function(e) { var t = e.value; e.value = (t.indexOf(".") >= 0) ? (t.substr(0, t.indexOf(".")) + t.substr(t.indexOf("."), 3)) : t; } var input = document.getElementById("amt"); // Add event listener input.addEventListener("input", function(e){ var max = parseFloat(input.max); this.setCustomValidity(""); console.log(this.value) if(parseFloat(this.value) > max){ this.value = max; } else if(this.validity.rangeUnderflow){ this.setCustomValidity("Does not reach the amount requirement"); } });

código HTML

 <input type="number" min="100" max="999.99" step=".01" name="amt" id="amt" oninput="validate(this)" required>
about 4 years ago · Juan Pablo Isaza
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!