From 911e65ca7d4f47ec18212375b4eb479c1c40acbe Mon Sep 17 00:00:00 2001 From: wyu <kknd09321@nate.com> Date: 금, 07 1월 2022 10:03:18 +0900 Subject: [PATCH] 연락처 입력시 하이픈 자동 입력 (지역, 핸드폰 번호) --- src/main/webapp/scripts/app/ispField/ispFieldAdd.controller.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) diff --git a/src/main/webapp/scripts/app/ispField/ispFieldAdd.controller.js b/src/main/webapp/scripts/app/ispField/ispFieldAdd.controller.js index 701a6d1..830e8ac 100644 --- a/src/main/webapp/scripts/app/ispField/ispFieldAdd.controller.js +++ b/src/main/webapp/scripts/app/ispField/ispFieldAdd.controller.js @@ -14,6 +14,7 @@ cancel : cancel, // �뙘�뾽 李� �떕湲� formSubmit : formSubmit, // �뤌 �쟾�넚 formCheck : formCheck, // �뤌 泥댄겕 + autoHyphenPhone : autoHyphenPhone // �뿰�씫泥� �엯�젰�떆 �븯�씠�뵂 �옄�룞 �엯�젰 }; $scope.vm = { @@ -36,9 +37,60 @@ return false; } + // �뿰�씫泥� �엯�젰�떆 �븯�씠�뵂 �옄�룞 �엯�젰 + function autoHyphenPhone() { + let phone = $scope.vm.form.tel + let seoul = $scope.vm.form.tel + + // �빖�뱶�룿 諛� 吏�諛� 吏��뿭踰덊샇 議곌굔 + phone.replace(/^[0-9]/g, ''); + // �꽌�슱 吏��뿭踰덊샇 議곌굔 + seoul.replace(/^[0-9]/g, ''); + var tmp = ''; + + if (phone.length < 4) { + return phone; + } else if (phone.length < 7) { + tmp += phone.substr(0, 3); + tmp += '-'; + tmp += phone.substr(3); + $scope.vm.form.tel = tmp; + } else if (seoul.substring(0, 2) === "02" && seoul.length === 9) { // �꽌�슱 吏��뿭踰덊샇 議곌굔 + tmp += seoul.substring(0, 2); + tmp += '-'; + tmp += seoul.substring(2, 5); + tmp += '-'; + tmp += seoul.substr(5); + $scope.vm.form.tel = tmp; + } else if (seoul.substring(0, 2) === "02" && seoul.length === 10) { // �꽌�슱 吏��뿭踰덊샇 議곌굔 + tmp += seoul.substring(0, 2); + tmp += '-'; + tmp += seoul.substring(2, 6); + tmp += '-'; + tmp += seoul.substr(6); + $scope.vm.form.tel = tmp; + } else if (phone.length < 11) { // �빖�뱶�룿 諛� 吏�諛� 吏��뿭踰덊샇 議곌굔 + tmp += phone.substr(0, 3); + tmp += '-'; + tmp += phone.substr(3, 3); + tmp += '-'; + tmp += phone.substr(6); + $scope.vm.form.tel = tmp; + } else { // �빖�뱶�룿 諛� 吏�諛� 吏��뿭踰덊샇 議곌굔 + tmp += phone.substr(0, 3); + tmp += '-'; + tmp += phone.substr(3, 4); + tmp += '-'; + tmp += phone.substr(7); + $scope.vm.form.tel = tmp; + } + return phone; + } + // �뤌 �쟾�넚 function formSubmit(condition) { $rootScope.spinner = true; + $scope.vm.form.tel = $scope.vm.form.tel.replace(/\-/g,''); // �쟾�솕踰덊샇瑜� 蹂대궪�븧 �븯�씠�뵂�쓣 �젣嫄고빐�꽌 DB�뿉 ���옣 var content = { code : $rootScope.preventXss($scope.vm.form.code), //肄붾뱶 -- Gitblit v1.8.0