how to validate that it is only a minimum of one digit and maximum two digits'

0

Good morning, everyone. I have a temperature field and only at least 5 degrees and maximum 30 degrees. What they see is my validation but not the quantity. They could help me.

      <label for="rep_legal">Temperatura</label>
      <input type="text" id="txt_temperatura" class="solo-numero">

     $('.solo-numero').keyup(function () {
         this.value = (this.value + '').replace(/[^0-9]/g, '');

     });
    
asked by Paul Guerrero 14.09.2017 в 01:12
source

3 answers

2

HTML5 includes a numeric input, which in addition to being friendlier (better user interaction with the control), allows you to define minimum and maximum values.

<label for="temperatura">Temperatura</label>
<input id="txt_temperatura" type="number" name="temperatura" min="5" max="30" placeholder="5 a 30">

Do not forget to define the DOCTYPE at the beginning of your HTML file to use HTML5: <!DOCTYPE html>

You can see more options at: HTML5 number input: A new field of numeric type in the form

    
answered by 14.09.2017 в 01:49
0

In addition to what you were told, you can do the following:

<input type="number" min="1" max="99" minlength="1" maxlength="2" />

With this additional to that you limit the limited values the number of characters in your form.

Greetings.

    
answered by 14.09.2017 в 02:29
0

I think that it would be better to validate it with html, the following would work for you

<input type="number" id="temp" min="1" max="99">

    
answered by 14.09.2017 в 01:25