이호영 이호영 2024-08-27
문자발소 > 받는사람 번호 입력하면 줄바꿈 기준으로 벨류 체크 후 등록
@d733f1d67bbcc9022e2b70e19ecf940c87e198da
src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp
--- src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp
+++ src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp
@@ -28,28 +28,32 @@
 	    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 @@
 	$('.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 @@
                             <th scope="row" class="vTop">받는사람</th>
                             <td class="putText">
                                 <div class="clearfix receipt_num">
+<!-- 									<div class="receipt_num_top"> -->
+<!-- 										<label for="callTo" class="label">받는 번호입력</label> -->
+
+<!-- 										<input type="text" id="callTo" name="callTo" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"  placeholder="번호를 입력하세요" 
+											onfocus="this.placeholder=''" onblur="this.placeholder='번호를 입력하세요'" style="width:340px;"> -->
+
+<!-- 										<button type="button" class="btnType btnType6 addCallToF">번호추가</button> -->
+<!-- 										<span><span class="vMiddle">*</span> 중복번호는 한번만 추가됩니다.</span> -->
+<!-- 									</div> -->
+
 									<div class="receipt_num_top">
-										<label for="callTo" class="label">받는 번호입력</label>
-										<input type="text" id="callTo" name="callTo" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"  placeholder="번호를 입력하세요" onfocus="this.placeholder=''" onblur="this.placeholder='번호를 입력하세요'" style="width:340px;">
-										<button type="button" class="btnType btnType6 addCallToF">번호추가</button>
-										<span><span class="vMiddle">*</span> 중복번호는 한번만 추가됩니다.</span>
+										<label for="" class="label">받는 번호입력</label>
+										<!-- <input type="text" placeholder="번호를 입력하세요" onfocus="this.placeholder=''" onblur="this.placeholder='번호를 입력하세요'" style="width:340px;"> -->
+<!-- 												oninput="this.value = this.value.replace(/[^0-9.\n]/g, '').replace(/(\..*)\./g, '$1');" -->
+										<textarea name="callTo" id="callTo" cols="30" rows="10" class="receipt_num" 
+												placeholder="번호를 입력하세요" 
+												onfocus="this.placeholder=''" 
+												onblur="this.placeholder='번호를 입력하세요'" 
+												style="width:340px;"></textarea>
+										<!-- <button type="button" class="btnType btnType6">번호추가</button> -->
+										<div class="btn_popup_wrap">
+											<button type="button" class="btnType btnType6 btn_add_number addCallToF">번호추가<i class="qmMark"></i></button>
+											<span style="display:block;margin:10px 0 0 0;"><span class="vMiddle">*</span> 중복번호는 한번만 추가됩니다.</span>
+											<div class="error_hover_cont send_hover_cont">
+												<p>휴대폰 번호 입력 시 해당 휴대폰 번호에 대한 형식이 어긋나거나 휴대폰 번호에 오류가 있는지 등을 검사하는 기능</p>
+												<span>(예시) 010-1234-0001(O) / 010-12345-0001(X)</span>
+											</div>
+										</div>
 									</div>
                                     <div class="receipt_num_midde">
                                         <div class="listType list01 callList_box">
Add a comment
List