Doubt about input attributes in HTML

1

Hello everyone. I am doing a Tabuada using HTML and PHP. The user types a number through the form and displays the number of the number. I wonder if I can put some attribute in <input type="number>" so that only positive numbers are displayed in the user selection field. Today my code looks like this:

<!--CAMPO PARA DIGITAR O NÚMERO-->
    <label>Número:</label>
    <input type="number" name="numero">

Thanks in advance!

    
asked by anonymous 01.03.2017 / 20:28

3 answers

3

The min and max properties of an input define the minimum and maximum values, respectively. <input type="number" min="0" name="numero">

    
01.03.2017 / 20:33
2

Since the input of type number , you can set the minimum and maximum values through the min and max attributes, respectively.

<input type="number" name="numero" min="0" max="9">

If you want any positive value, just remove the max attribute.

    
01.03.2017 / 20:31
2

As user Thiago has already replied, you can use the min and max attributes of HTML5.

The only problem is that they will not work on older browsers. In these cases it is always a good idea to use a polyfill to ensure that older browsers also have functionality.

A cool plugin for jQuery that has compatibility is Stepper .

    
01.03.2017 / 20:50