하석형 하석형 05-12
250512 하석형 회원관리 휴대폰, 전화번호 입력시 하이픈 표기
@6bd8203abfb90998117176fad955b82b379a6576
client/resources/js/validateParams.js
--- client/resources/js/validateParams.js
+++ client/resources/js/validateParams.js
@@ -114,23 +114,25 @@
 
     // 휴대폰번호
     validateMblNo(key) {
-      if (this.isEmpty(key)) {
+      const raw = key.replace(/-/g, ''); // 하이픈 제거
+
+      if (this.isEmpty(raw)) {
         alert("휴대폰번호를 입력하세요.");
         this.$refs.mblTelno.focus();
         return false;
       } // 입력 여부
-      if (!this.minLength(key, 10)) {
+      if (!this.minLength(raw, 10)) {
         alert("휴대폰번호는 10자 이상으로 입력하세요.");
         this.$refs.mblTelno.focus();
         return false;
       } // 최소 길이
-      if (!this.maxLength(key, 11)) {
+      if (!this.maxLength(raw, 11)) {
         alert("휴대폰번호는 11자 이하로 입력하세요.");
         this.$refs.mblTelno.focus();
         return false;
       } // 최대 길이
       const telRegex = /^01[016789][0-9]{3,4}[0-9]{4}$/;
-      if(!telRegex.test(key)) {
+      if(!telRegex.test(raw)) {
         alert("휴대폰번호 형식이 맞지 않습니다.");
         this.$refs.mblTelno.focus();
         return false;
client/views/component/userInfo/UserInfoInsert.vue
--- client/views/component/userInfo/UserInfoInsert.vue
+++ client/views/component/userInfo/UserInfoInsert.vue
@@ -45,17 +45,19 @@
                   " />
             </div>
             <!-- <template v-if="showOpt.isMblNo || showOpt.isTelNo"> -->
-              <div v-if="showOpt.isMblNo" class="layout">
-                <label class="form-title"><span>*</span>휴대폰번호</label>
-                <input type="text" class="form-control sm" ref="mblTelno" v-model="mbrVO.mblTelno" minlength="10"
-                  maxlength="11" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\.*)/g, '');"
-                  placeholder="휴대폰번호를 입력하세요." />
-              </div>
+            <div v-if="showOpt.isMblNo" class="layout">
+              <label class="form-title"><span>*</span>휴대폰번호</label>
+              <input type="text" class="form-control sm" ref="mblTelno" v-model="mbrVO.mblTelno"
+                @input="inputFormatPhone"
+                maxlength="13"
+                placeholder="휴대폰번호를 입력하세요." />
+            </div>
             <!-- </template> -->
             <div v-if="showOpt.isTelNo" class="layout">
               <label class="form-title">전화번호</label>
               <input type="text" class="form-control sm" ref="telno" v-model="mbrVO.telno"
-                oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\.*)/g, '');"
+                @input="inputFormatTel"
+                maxlength="13"
                 placeholder="전화번호를 입력해주세요." />
             </div>
             <!-- <template v-if="showOpt.isEml || showOpt.isSmsAgree || showOpt.isEmlAgree"> -->
@@ -293,16 +295,32 @@
     },
     // 표기변경
     changeFormat() {
-      // 휴대폰 번호
-      let mblNo = this.mbrVO.mblTelno;
-      if (mblNo != null) {
-        this.mbrVO.mblTelno = mblNo.replace(/[^0-9]/g, "");
+      // 휴대폰번호 포맷
+      const mbl = this.mbrVO.mblTelno?.replace(/[^0-9]/g, '') || '';
+      if (mbl.length === 10) {
+        this.mbrVO.mblTelno = mbl.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
+      } else if (mbl.length === 11) {
+        this.mbrVO.mblTelno = mbl.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
       }
-      // 전화번호
-      let telNo = this.mbrVO.telno;
-      if (telNo != null) {
-        this.mbrVO.telno = telNo.replace(/[^0-9]/g, "");
+
+      // 전화번호 포맷
+      const tel = this.mbrVO.telno?.replace(/[^0-9]/g, '') || '';
+      if (tel.startsWith('02')) {
+        // 서울 지역번호 (2자리)
+        if (tel.length === 9) {
+          this.mbrVO.telno = tel.replace(/(\d{2})(\d{3})(\d{4})/, '$1-$2-$3');
+        } else if (tel.length === 10) {
+          this.mbrVO.telno = tel.replace(/(\d{2})(\d{4})(\d{4})/, '$1-$2-$3');
+        }
+      } else {
+        // 나머지 지역번호 (3자리)
+        if (tel.length === 10) {
+          this.mbrVO.telno = tel.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
+        } else if (tel.length === 11) {
+          this.mbrVO.telno = tel.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
+        }
       }
+
       // 이메일
       if (this.mbrVO.eml != null) {
         const email = this.mbrVO.eml.split("@");
@@ -319,6 +337,52 @@
             this.email.select = "self";
             this.email.address = email[1];
             break;
+        }
+      }
+    },
+
+    // 휴대폰 번호 입력 포맷
+    inputFormatPhone(event) {
+      let input = event.target.value.replace(/[^0-9]/g, '');
+
+      if (input.length <= 3) {
+        this.mbrVO.mblTelno = input;
+      } else if (input.length <= 6) {
+        this.mbrVO.mblTelno = input.slice(0, 3) + '-' + input.slice(3);
+      } else if (input.length === 10) {
+        // 10자리는 3-3-4
+        this.mbrVO.mblTelno = input.slice(0, 3) + '-' + input.slice(3, 6) + '-' + input.slice(6);
+      } else {
+        // 기본은 3-4-4
+        this.mbrVO.mblTelno = input.slice(0, 3) + '-' + input.slice(3, 7) + '-' + input.slice(7, 11);
+      }
+    },
+
+    // 전화번호 입력 포맷
+    inputFormatTel(event) {
+      let input = event.target.value.replace(/[^0-9]/g, '');
+
+      if (input.startsWith('02')) {
+        // 서울 지역번호 (2자리)
+        if (input.length <= 2) {
+          this.mbrVO.telno = input;
+        } else if (input.length <= 5) {
+          this.mbrVO.telno = input.slice(0, 2) + '-' + input.slice(2);
+        } else if (input.length <= 9) {
+          this.mbrVO.telno = input.slice(0, 2) + '-' + input.slice(2, 5) + '-' + input.slice(5);
+        } else {
+          this.mbrVO.telno = input.slice(0, 2) + '-' + input.slice(2, 6) + '-' + input.slice(6, 10);
+        }
+      } else {
+        // 나머지 지역번호 (3자리)
+        if (input.length <= 3) {
+          this.mbrVO.telno = input;
+        } else if (input.length <= 6) {
+          this.mbrVO.telno = input.slice(0, 3) + '-' + input.slice(3);
+        } else if (input.length <= 10) {
+          this.mbrVO.telno = input.slice(0, 3) + '-' + input.slice(3, 6) + '-' + input.slice(6);
+        } else {
+          this.mbrVO.telno = input.slice(0, 3) + '-' + input.slice(3, 7) + '-' + input.slice(7, 11);
         }
       }
     },
@@ -411,6 +475,14 @@
         data.pswd = null;
       }
 
+      // 휴대폰 번호
+      data.mblTelno = this.mbrVO.mblTelno.replace(/-/g, ''); // 하이픈 제거
+
+      // 전화 번호
+      if(this.mbrVO.telno != null) {
+        data.telno = this.mbrVO.telno.replace(/-/g, "");
+      }
+
       // 이메일
       data.eml = this.emailSum();
 
Add a comment
List