new Vue({ el: "#app", data: { firstRRN: [], firstRRNView: '', secondRRN: [], secondRRNView: '', }, methods: { firstRRNCheck(e) { if (this.isNumber(e) && this.firstRRN.length < 6) { this.firstRRN.push(e) } else if (e === null && this.firstRRN.length > 0) { this.firstRRN.pop() } this.firstRNNView = this.firstRRN.join('') }, secondRRNCheck(e) { if (this.isNumber(e) && this.secondRRN.length < 7) { this.secondRRN.push(e) } else if (e === null && this.secondRRN.length > 0) { this.secondRRN.pop() } let convertStr = '' if (this.secondRRN.length > 0) { convertStr = this.secondRRN[0] + String(this.secondRRN.join('')).replace(/./g, '•').substr(1) } this.secondRRNView = convertStr }, isNumber(data) { if (/^[0-9]$/g.test(data)) { return true; } else { return false; } }, validateRRN() { if (this.firstRRN.length < 6 && this.secondRRN.length < 7) return false let N = 0 for (let i = 1; i < 7; i++) { N += this.firstRRN[i - 1] * (i + 1) } for (let j = 1; j < 7; j++) { if (j < 3) { N += this.secondRRN[j - 1] * (j + 7) } else { N += this.secondRRN[j - 1] * (j - 1) } } return ((11 - (N % 11)) % 10) === Number(this.secondRRN[6]) }, resultRRN() { return this.firstRRN.join('') + '-' + this.secondRRN.join('') } }, })
<div id="app"> 주민등록번호 <br/> <input type="text" inputmode="numeric" pattern="[0-9]*" maxlength="6" @input="firstRRNCheck($event.data)" v-model="firstRRNView" class="tf_register" placeholder="주민번호 앞자리"> - <input type="text" pattern="[0-9]*" inputmode="numeric" maxlength="7" @input="secondRRNCheck($event.data)" v-model="secondRRNView" placeholder="OOOOOOO"> <div> Result : {{resultRRN()}} {{validateRRN()}} </div> </div>