Here I have written a code in vue.js. This code is for while user enters a number in a price field then after three digit comma "," will prompt dynamically. SO this functionality is expected and it is working fine but the issue is while we try to enter a dot '.' manually it is not allowing us enter the dot. SO in this script i want to allow the user to enter a dot '.' manually. So please help me to solve this issue.
<div id="vue">
<input type="text" v-model="price" />
</div>
<script>
new Vue({
el: '#vue',
data: {
price: 0
},
watch: {
price: function(newValue) {
const result = newValue.replace(/\D/g, "")
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
Vue.nextTick(() => this.price = result);
}
}
});
</script>