From d733f1d67bbcc9022e2b70e19ecf940c87e198da Mon Sep 17 00:00:00 2001 From: hylee Date: Tue, 27 Aug 2024 15:00:14 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AC=B8=EC=9E=90=EB=B0=9C=EC=86=8C=20>=20?= =?UTF-8?q?=EB=B0=9B=EB=8A=94=EC=82=AC=EB=9E=8C=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=ED=95=98=EB=A9=B4=20=EC=A4=84=EB=B0=94?= =?UTF-8?q?=EA=BF=88=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EB=B2=A8?= =?UTF-8?q?=EB=A5=98=20=EC=B2=B4=ED=81=AC=20=ED=9B=84=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsp/web/msgdata/MsgDataSMLView.jsp | 206 +++++++++++------- 1 file changed, 132 insertions(+), 74 deletions(-) diff --git a/src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp b/src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp index 074594b9..fb4a1873 100644 --- a/src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp +++ b/src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp @@ -28,28 +28,32 @@ $(document).ready(function(){ validationMode:"highlight", placeholder:"복사(Ctrl+C)한 내용을 여기에 붙여넣기(Ctrl+V) 해주세요.", //fit columns to width of table (optional) resizableColumns:false, + columnDefaults:{ // 공통설정 + hozAlign: "center", + headerHozAlign: "center", + editor: "input", + editor: false + }, columns:[ //Define Table Columns {formatter:"rowSelection", headerHozAlign:"center", titleFormatter:"rowSelection",clipboard:false, hozAlign:"center", width:5, headerSort:false, cellClick:function(e, cell){ cell.getRow().toggleSelect(); }}, // {formatter:"rownum", align:"center", title:"No", hozAlign:"center", headerHozAlign:"center", field:"No", width:30}, {formatter:"rownum", align:"center" ,title:"No", hozAlign:"center", headerHozAlign:"center", width:40}, - {title:"이름", hozAlign:"center", headerHozAlign:"center", field:"name", editor:"input", validator:["maxLength:12"], cellEdited:function(cell){ + {title:"이름", field:"name", validator:["maxLength:12"], cellEdited:function(cell){ fnReplCell(); }}, - {title:"휴대폰", hozAlign:"center", headerHozAlign:"center", field:"phone", editor:"input", width:100, validator:["required","minLength:10", "maxLength:12"], cellEdited:function(cell){ - fnDuplPhone(); - }}, - {title:"[*1*]", hozAlign:"center", headerHozAlign:"center", field:"rep1", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ + {title:"휴대폰", field:"phone", width:100, validator:["required","minLength:10", "maxLength:12"]}, + {title:"[*1*]", field:"rep1", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ fnReplCell(); }}, - {title:"[*2*]", hozAlign:"center", headerHozAlign:"center", field:"rep2", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ + {title:"[*2*]", field:"rep2", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ fnReplCell(); }}, - {title:"[*3*]", hozAlign:"center", headerHozAlign:"center", field:"rep3", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ + {title:"[*3*]", field:"rep3", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ fnReplCell(); }}, - {title:"[*4*]", hozAlign:"center", headerHozAlign:"center", field:"rep4", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ + {title:"[*4*]", field:"rep4", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){ fnReplCell(); }}, @@ -1083,73 +1087,104 @@ $(document).ready(function (){ $('.addCallToF').click(function(){ var callToNum = $('#callTo').val(); - if(callToNum == null || callToNum == ""){ - - alert("받는사람 번호를 입력해 주세요."); - return false; - - }else if(!checkHpNum(callToNum)){ - - alert("올바른 전화번호를 입력해 주세요."); - $('#callTo').val(""); - return false; + if (callToNum == null || callToNum == "") { + alert("받는사람 번호를 입력해 주세요."); + return false; } + + const textarea = $('#callTo'); + const numbers = textarea.val().split('\n') + .map(num => num.trim()) + .filter(num => num !== ""); + + console.log('입력된 번호들 : ', numbers); + + // 현재 테이블에 있는 데이터 가져오기 + const existingRows = tableL.getData(); + const existingNumbers = new Set(existingRows.map(row => row.phone.replace(/[^0-9]/g, ''))); // 숫자만 남겨서 중복 비교 + + let duplicateCount = 0; // 중복 번호 개수를 저장할 변수 + let invalidNumbers = []; // 유효하지 않은 번호를 저장할 배열 + + // 각 번호를 테이블에 추가 (중복 검사 및 포맷팅 포함) + numbers.forEach(number => { + const formattedNumber = formatPhoneNumber(number); // 번호 표준화 +// console.log('number : ', number) +// console.log('formattedNumber : ', formattedNumber) + const cleanedNumber = formattedNumber.replace(/[^0-9]/g, ''); // 숫자만 남김 + if (!existingNumbers.has(cleanedNumber)) { // 중복 번호 체크 + if (isValidPhoneNumber(formattedNumber)) { // 유효성 검사 + tableL.addRow({ phone: formattedNumber }); // 표준화된 번호로 추가 + existingNumbers.add(cleanedNumber); // 추가된 번호를 기존 목록에 추가 + } else { +// alert(`유효하지 않은 번호 형식: ${number}`); + invalidNumbers.push(number); // 유효하지 않은 번호를 배열에 추가 + } + } else { + duplicateCount++; // 중복 번호가 발견될 때마다 카운트를 증가 + } + }); + + // 중복 번호 개수를 #rowDupCnt 요소에 표시 + $("#rowDupCnt").text(duplicateCount); + + updateTotCnt(tableL.getRows().length); - //핸드폰 번호에 '-' 문자 제거하기 - callToNum = removeDash(callToNum); - - //기존 받는사람 연락처 모두 불러오기 - var data = tableL.getRows(); - var tableData = []; - var dpCnt = 0; - for(var i=0; i < tableL.getRows().length; i++){ - - if(callToNum == data[i].getData().phone){ - - dpCnt++; - - } - - } - - if(dpCnt > 0){ - - alert("받는사람 리스트에 동일한 연락처가 있습니다."); - $('#callTo').val(""); - return false; - - }else{ - - tabledata = [{phone: callToNum},]; - - //빈 row 데이터 삭제하기 - var befData = tableL.getRows(); - var totLen = tableL.getRows().length; - - for(var i=0; i < totLen; i++){ - - tableData.push({phone: data[i].getData().phone.trim(), name: data[i].getData().name}); - - } - - //연락처 추가해 주기 - addPhoneInfo(tabledata); - - //tableL.addData(tabledata); - - //전체 데이터 갯수 구하기 - //totRows = tableL.getRows().length; - //updateTotCnt(totRows); - - //결제 금액 구하기 - //totalPriceSum(totRows); - - $('#callTo').val(""); - - } + // 유효하지 않은 번호가 있으면 alert로 표시 + console.log('invalidNumbers : ', invalidNumbers); + if (invalidNumbers.length > 0) { + alert('유효하지 않은 번호 형식: \n'+ invalidNumbers.join('\n')); + } + // textarea 초기화 + textarea.val(''); // jQuery 객체에서 값을 초기화할 때는 .val('') 사용 }); + // 유효한 번호인지 확인하는 함수 + function isValidPhoneNumber(phone) { + // 숫자만 추출 + const numberOnly = phone.replace(/\D/g, ''); + + // 유효한 형식 체크 + return ( + (numberOnly.startsWith("010") && numberOnly.length === 11) || // 010으로 시작하고 11자리 + (/^01[1-9]/.test(numberOnly) && numberOnly.length === 10) || // 011~019로 시작하고 10자리 + (numberOnly.startsWith("050") && numberOnly.length === 12) // 050X로 시작하고 12자리 + ); + } + + function formatPhoneNumber(phone) { + // 숫자만 남기기 + let cleanedPhone = phone.replace(/\D/g, ''); // 모든 숫자가 아닌 문자 제거 + console.log('cleanedPhone : ', cleanedPhone); + + // 앞에 0이 추가된 경우 처리 + if (cleanedPhone.length === 10 && cleanedPhone.startsWith("10")) { + // 10으로 시작하는 10자리 번호는 앞에 0을 추가하여 11자리로 만듦 + cleanedPhone = "0" + cleanedPhone; + }else if (cleanedPhone.length === 9 && (cleanedPhone.startsWith("11") || cleanedPhone.startsWith("16") || cleanedPhone.startsWith("19"))) { + // 11, 16, 19로 시작하는 9자리 번호는 앞에 0을 추가하여 10자리로 만듦 + cleanedPhone = "0" + cleanedPhone; + } + + // 번호 형식 변환 + if (cleanedPhone.startsWith("010") && cleanedPhone.length === 11) { + // 010-1234-5678 형식 + return cleanedPhone.substring(0, 3) + '-' + cleanedPhone.substring(3, 7) + '-' + cleanedPhone.substring(7); + } else if ((/^01[1-9]/.test(cleanedPhone)) && cleanedPhone.length === 10) { + // 01X-123-5678 형식 + return cleanedPhone.substring(0, 3) + '-' + cleanedPhone.substring(3, 6) + '-' + cleanedPhone.substring(6); + } else if (cleanedPhone.startsWith("050") && cleanedPhone.length === 12) { + // 050X-1234-5678 형식 + return cleanedPhone.substring(0, 4) + '-' + cleanedPhone.substring(4, 8) + '-' + cleanedPhone.substring(8); + } + + // 원본 반환 (표준 형식으로 변환되지 않으면) + return phone; + } + + + //받는사람 전체삭제 버튼 처리 $('.all_del').click(function(){ @@ -4094,11 +4129,34 @@ function getMjMsgSentListAll(pageNo) { 받는사람
+ + + + + + + + +
- - - - * 중복번호는 한번만 추가됩니다. + + + + + +
+ + * 중복번호는 한번만 추가됩니다. +
+

휴대폰 번호 입력 시 해당 휴대폰 번호에 대한 형식이 어긋나거나 휴대폰 번호에 오류가 있는지 등을 검사하는 기능

+ (예시) 010-1234-0001(O) / 010-12345-0001(X) +
+