---
description: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
---

# Character limit on tag type input number (ok)

**Ví dụ 1:** [**https://codepen.io/jpI/pen/yERodB**](https://codepen.io/jpI/pen/yERodB)

```
<input class="zipcode-number" type="number" min="0" max="99999" maxlength="5" name="" id="zipCode">
```

```
var inputQuantity = [];
    $(function() {     
      $(".zipcode-number").on("keyup", function (e) {
        var $field = $(this),
            val=this.value,
            $thisIndex=parseInt($field.data("idx"),10); 
        if (this.validity && this.validity.badInput || isNaN(val) || $field.is(":invalid") ) {
            this.value = inputQuantity[$thisIndex];
            return;
        } 
        if (val.length > Number($field.attr("maxlength"))) {
          val=val.slice(0, 5);
          $field.val(val);
        }
        inputQuantity[$thisIndex]=val;
      });      
    });
```

**Ví dụ 2:** [**https://jsfiddle.net/ssuryar/nadn72jv/**](https://jsfiddle.net/ssuryar/nadn72jv/)

```
 <input type="number" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" onKeyDown="if(this.value.length==10 && event.keyCode!=8) return false;">
```

