Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit digit number in vue input?

My goal is to limit the number of digit user can enter in the input field. So a user can only input 10 digits. I tried min and max still doesn't work

Here's the code

        <input
          v-model="amount"
          type="number"
        >


        <script>
             export default {
                  data() {
                      return { 
                          amount: 7800
                      }
                   }

              }

        </script>

Right now i can add more than 10 digits

like image 564
sinusGob Avatar asked Nov 28 '22 01:11

sinusGob


1 Answers

Replace this:

<input v-model="amount" type="number">

to

<input v-model="amount"
        oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
        type = "number"
        maxlength = "10"
/>
like image 74
Amarat Avatar answered Dec 09 '22 19:12

Amarat