1

I am trying to restrict the user to type decimal point as below.

 <b-form-input
          size="sm"
          type="number"
          v-model.number="lots"
          class="inputprice"
          style="width:40%"
          oninput="javascript: if (this.value === '.') return;"
        >{{ lots }}
 </b-form-input>

But this attempt not working. Anyone knows how can I do it inside on input attribute?

1 Answers1

0

You can use parseInt to convert the input value to an integer as follows:

new Vue({
  el:"#app",
  data(){
    return{
      lots:0
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <input
    type="number"
    v-model.number="lots"
    class="inputprice"
    style="width:40%"
    oninput="this.value = parseInt(this.value);"
  />{{ lots }}
</div>
Majed Badawi
  • 27,616
  • 4
  • 25
  • 48