Spring

회원가입

sian han 2022. 5. 19. 00:15

▶ 입력된 이메일, 전화번호 합쳐서 DB에 저장하기

  - 파라미터로 email1,email2,email3 받아온 후에 아래과정을 통해 합쳐서 VO 에 넣으면 됨

    VO 는 useBean으로 불러옴

 

  String hp="", email="";
   if(hp2!=null && !hp2.isEmpty() && hp3!=null && !hp3.isEmpty()){
	   hp=hp1+"-"+hp2+"-"+hp3;
   }
   
   if(email1!=null && !email1.isEmpty()){
		if(email2.equals("etc")){
		   if(email3!=null && !email3.isEmpty()){			
				email=email1+"@"+email3;		
		   }
		}else{
			email=email1+"@"+email2;
		}
   }

 

 

▷ DB에 저장한 hp 쪼개서 tf에 뿌리기

 

 

vo.getHP 를 통해 String hp 변수에 넣어놓은 후 아래와 같이 쪼갠다

String hp1="";
	String hp2="";
	String hp3="";
	String hp=vo.getHp();
	if(hp!=null && !hp.isEmpty()){
	   String[] hpArr=hp.split("-");
	   hp1=hpArr[0];
	   hp2=hpArr[1];
	   hp3=hpArr[2];
	}

 

 

body tf에 값 넣기

<label for="hp1">핸드폰</label>&nbsp;
                <select name="hp1" id="hp1"
                    title="휴대폰 앞자리">
                    <option value="010"
                        <%if(hp1.equals("010")){ %>
                            selected="selected"
                        <%} %>
                    >010</option>
                    <option value="011" 
                    <%if(hp1.equals("011")){ %>
                            selected="selected"
                        <%} %>
                        >011</option>

                    <option value="016"
                    <%if(hp1.equals("016")){ %>
                            selected="selected"
                        <%} %>
                        >016</option>
                    <option value="017"
                    <%if(hp1.equals("017")){ %>
                            selected="selected"
                        <%} %>
                        >017</option>
                    <option value="018"
                    <%if(hp1.equals("018")){ %>
                            selected="selected"
                        <%} %>
                        >018</option>
                    <option value="019"
                    <%if(hp1.equals("019")){ %>
                            selected="selected"
                        <%} %>
                        >019</option>
                </select> - 
                <input type="text" name="hp2" id="hp2" maxlength="4"
                    title="휴대폰 가운데자리" class="width_80"
                    value="<%=hp2%>">- 
                <input type="text"
                    name="hp3" id="hp3" maxlength="4" 
                    title="휴대폰 뒷자리" class="width_80"
                    value="<%=hp3%>">
				</div>
				<div>

이렇게 넣어주면 댐

 

 

 

 

▷ DB에 저장한 email 쪼개서 tf에 뿌리기

String email1="";
	String email2="";
	
	String email = vo.getEmail();
	if(email !=null && email.isEmpty()){
		String[] emailArr = email.split("@");
		email1 = emailArr[0];
		email2 = emailArr[1];
	}
	
	String[] emailList= {"naver.com","hanmail.net","nate.com","gmail.com"};
	//h@nate.com , k@herb.com,""
	boolean isEtc = false; //직접입력이면 true로 바꿔줌
	int count =0;
	
	for(int i =0;i<emailList.length;i++){
		if(emailList[i].equals(email2)){
			count++;
			break;
		}
	}
	if(count==0){
		isEtc = true;
	}

  = > vo에서 get 해온 email 값이 있을경우 배열을 split 해서 변수에 각각담는다

for 문을 돌려서 변수의 값이 배열안의 값과 일치할경우 변수 count ++ 실행한다.

count 가 0보다 클 경우 isEtc(직접입력) 값을 true 로 바꾼다 

 

 

body

<label for="email1">이메일 주소</label> 
            <input type="text" name="email1"
                id="email1" title="이메일주소 앞자리" value="<%=email1%>">@ 
            <select name="email2"
                id="email2" title="이메일주소 뒷자리">
                <option value="naver.com"
                    <%if(email2.equals("naver.com")){ %>
                        selected="selected"
                    <%} %>
                >naver.com</option>
                <option value="hanmail.net"
                    <%if(email2.equals("hanmail.net")){ %>
                            selected="selected"
                        <%} %>
                >hanmail.net</option>
                <option value="nate.com"
                    <%if(email2.equals("nate.com")){ %>
                        selected="selected"
                    <%} %>
                >nate.com</option>
                <option value="gmail.com"
                    <%if(email2.equals("gmail.com")){ %>
                        selected="selected"
                    <%} %>
                >gmail.com</option>
                <option value="etc"
                    <%if(isEtc){ %>
                        selected="selected"
                    <%} %>
                >직접입력</option>
            </select> 
            <input type="text" name="email3" id="email3"
                title="직접입력인 경우 이메일주소 뒷자리" 
                <%if(isEtc){%>
                    style= "visibility:visible"
                    value = "<%=email2 %>"
                <% }else{%>
                    style="visibility:hidden"
                <%} %>
                >

  = > email1은 그냥 넣어주면되고

email2 가 직접입력이 아닐경우 (isEtc =false) value값과 email2를 비교하여 같다면 해당 콤보박스를 select 한다

email2가 직접입력일경우 (isEtc =true) 직접입력tf(email3) 칸이 visible 로 변경되고 해당칸에 email2 변수의 값을 넣는다

 

 

 

 

 

 

 

▶ 아이디 정규식 (문자나 숫자)


  - 정규식 /^[a-zA-Z0-9_]+$/g
    a에서 z 사이의 문자, A~Z사이의 문자, 0 에서 9사이의 숫자나 _로 시작하거나 끝나야 한다는 의미
    닫기 대괄호(]) 뒤의 + 기호는 이 패턴이 한 번 또는 그 이상 반복된다는 의미

function validate_userid(id){
	var pattern = new RegExp(/^[a-zA-Z0-9_]+$/g);
	return pattern.test(id);
}

 

 

 

 

▶ 전화번호 정규식 (숫자)

 

  - 정규식 /^[0-9]*$/g
    0 에서 9사이의 숫자로 시작하거나 끝나야 한다는 의미 (^는 시작, $는 끝을 의미)
    닫기 대괄호(]) 뒤의 * 기호는 0번 이상 반복

 

function validate_tel(tel){
	var pattern = new RegExp(/^[0-9]*$/g);
	return pattern.test(tel); ; //정규식과 일치하면 true
}

 

 

'Spring' 카테고리의 다른 글

[jsp] 표현언어  (0) 2022.05.22
[jsp] 모델2 기반의 MVC 패턴 게시판의 흐름  (0) 2022.05.22
[jsp] 모델2 기반의 MVC 패턴  (0) 2022.05.18
[jsp] 에러  (0) 2022.05.17
[jsp] 쿠키 / 세션  (0) 2022.05.16