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

133
Views
Problem when validating an input with javascript

Currently I am validating an input of type number with javascript, this must be between 2 and 12, but it does not allow me to choose between 10 or 11.

$(".m-max-212").on("input", function() {
  var value = $(this).val();
  if (value !== "" && value.indexOf(".") === -1) {
    $(this).val(Math.max(Math.min(value, 12), 1));
    $(".cm-max-299").val(0);
  }
});

$(".cm-max-299").on("input", function() {
  var value = $(this).val();
  if ($(".m-max-212").val() < 12) {
    if (value !== "" && value.indexOf(".") === -1) {
      $(this).val(Math.max(Math.min(value, 99), 0));
    }
  } else {
    $(this).val(0);
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
  <input type="number" class="m-max-212" placeholder="">
</div>
<div class="input-group mb-2">
  <input type="number" class="cm-max-299" placeholder="">
</div>

What am I doing wrong?

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!