정규식 - 3자리 숫자 마다 콤마 찍기
3자리 숫자마다 콤마 찍기
by jinam yu
HTML
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
<form class="p-4">
<div class="form-group">
<label >숫자를 입력해 보세요.</label>
<input type="text" class="form-control" v-model="number" />
</div>
<div class="form-group">
<input class="form-control" type="text" :value="output" readonly />
</div>
</form>
</div>
CSS
html, body {
background-color: #f8f9fa;
}
Vue
new Vue({
el: "#app",
data: {
number: "12345678",
},
computed: {
output() {
return this.number.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
},
methods: {},
mounted() {}
})