There are several ways that can be copied from the following references: https://stackoverflow.com/questions/18510845/maxlength-ignored-for-input-type-number-in-chrome I used the following code.
For a maximum of 16 digits in the form for filling in the Population Identification Number (KTP).
<div class="form-group"> <label><b>NOMOR INDUK KTP</b></label> <input type="number" pattern="/^-?\d+\.?\d*$/" onKeyPress="if(this.value.length==16) return false;" / class="form-control" name="nik_ktp" placeholder="" required> </div>
Good luck.