How to validate the number of digits entered in an input type number?

1

I am using bootstrap jvalidator but I can not validate the number of digits entered in an input type number

<div class="form-group">
    <label class="col-sm-2 control-label coLor-letter" for="textinput">No Vin</label>
    <div class="col-sm-4">
      <input name="line" type="number"   class="form-control input-style" data-error=""  maxlength="12" >
      <div class="help-block with-errors"></div>
    </div>
  </div>
    
asked by Fercho Jerez 04.08.2016 в 08:12
source

2 answers

2

The maxlength property will only work with <input type="text"> since it limits the number of characters in a text string.

For a <input type="number"> the properties max and min are used.

Example, if you want that you can only enter a value between 1 and 999:

<input type="number" min="1" max="999" />

    
answered by 04.08.2016 / 12:01
source
1

I think the solution is as simple as calculating the length of value of the field in question:

<input type="text" id="my_input" value="my_value" >

var digitos = document.querySelector('#my_input').value.length
    
answered by 04.08.2016 в 09:24