jsp - 각종 체크 &우편번호

by 조쉬 posted Mar 28, 2021
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

1. 다음 우편번호 api 사용 -> 예제->사용자 지정 예제 복사 -> 스크립트 부분에 붙여넣기 -> input type  id 만 교체 

2. 비밀번호 확인 및 아이디 개수 체크

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE  >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.1.0.js">
    
</script>
 
 
 
<script>
    $(document).ready(function() {
        //아이디 중복체크
 
        $("#userid").keyup(function() {
            //사용자가 입력한 아이디
 
            var userid = $("#userid").val();
 
            var param = "userid=" + userid;
 
            if (userid.length >= 4) { //최소 글자수 이상
 
                //아이디 체크
 
                $.ajax({
                    type : "post",
                    url : "/web02/member_servlet/idcheck.do",
                    data : param,
                    success : function(result) {
 
                        $("#span_id").html(result);
 
                    }
 
                })
 
            }
 
        });
 
        //버튼클릭 이벤트
        $("#btnJoin").click(function() {
            var userid = $("#userid").val();
            var name = $("#name").val();
            var passwd = $("#passwd").val();
            var passwd2 = $("#passwd2").val();
 
            
            if(userid.length<4){
                
                alert("아이디를 입력하세요");
                $("#userid").focus();
                return;
            }
            
            if (name == "") {
 
                alert("이름을 입력하세요");
                $("#name").focus();
                return;
            }
 
            if (passwd != passwd2) {
 
                alert("비밀번호가 일치하지 않습니다.");
                $("#passwd2").val("");
 
                return;
            }
 
            //폼데이터를 서버에 제출
            document.form1.submit();
 
        });
 
    });
</script>
 
<script src="http://dmaps.daum.net/map_js_init/postcode.v2.js"></script>
<script>
    function sample6_execDaumPostcode() {
        new daum.Postcode(
                {
                    oncomplete : function(data) {
                        // 팝업에서 검색결과 항목을 클릭했을때 실행할 코드를 작성하는 부분.
 
                        // 각 주소의 노출 규칙에 따라 주소를 조합한다.
                        // 내려오는 변수가 값이 없는 경우엔 공백('')값을 가지므로, 이를 참고하여 분기 한다.
                        var fullAddr = ''// 최종 주소 변수
                        var extraAddr = ''// 조합형 주소 변수
 
                        // 사용자가 선택한 주소 타입에 따라 해당 주소 값을 가져온다.
                        if (data.userSelectedType === 'R') { // 사용자가 도로명 주소를 선택했을 경우
                            fullAddr = data.roadAddress;
 
                        } else { // 사용자가 지번 주소를 선택했을 경우(J)
                            fullAddr = data.jibunAddress;
                        }
 
                        // 사용자가 선택한 주소가 도로명 타입일때 조합한다.
                        if (data.userSelectedType === 'R') {
                            //법정동명이 있을 경우 추가한다.
                            if (data.bname !== '') {
                                extraAddr += data.bname;
                            }
                            // 건물명이 있을 경우 추가한다.
                            if (data.buildingName !== '') {
                                extraAddr += (extraAddr !== '' ? ', '
                                        + data.buildingName : data.buildingName);
                            }
                            // 조합형주소의 유무에 따라 양쪽에 괄호를 추가하여 최종 주소를 만든다.
                            fullAddr += (extraAddr !== '' ? ' (' + extraAddr
                                    + ')' : '');
                        }
 
                        // 우편번호와 주소 정보를 해당 필드에 넣는다.
                        document.getElementById('sample6_postcode').value = data.zonecode; //5자리 새우편번호 사용
                        document.getElementById('sample6_address').value = fullAddr;
 
                        // 커서를 상세주소 필드로 이동한다.
                        document.getElementById('sample6_address2').focus();
                    }
                }).open();
    }
</script>
 
</head>
<body>
 
 
    <h2>회원가입</h2>
 
 
    <form name="form1" method="post" action="/web02/member_servlet/join.do">
 
        <table border="1" width="700px">
            <tr>
                <td>이름</td>
                <td><input type="text" name="name" id="name"></td>
            </tr>
 
 
            <tr>
                <td>아이디</td>
                <td><input type="text" name="userid" id="userid"> <span
                    id="span_id"></span></td>
            </tr>
 
 
            <tr>
                <td>비밀번호</td>
                <td><input type="password" name="passwd" id="passwd"></td>
            </tr>
 
 
            <tr>
                <td>비밀번호확인</td>
                <td><input type="password" name="passwd2" id="passwd2"></td>
            </tr>
 
 
            <tr>
                <td>이메일</td>
                <td><input type="email" name="email" id="email"></td>
            </tr>
 
 
            <tr>
                <td>폰번호</td>
                <td><input type="text" name="hp" id="hp"></td>
            </tr>
 
 
            <tr>
                <td>우편번호</td>
                <!-- readonly 읽기만전용 -->
                <td><input type="text" name="zipcode" id="sample6_postcode"
                    readonly> <input type="button"
                    onclick="sample6_execDaumPostcode()" value="우편번호 찾기"></td>
            </tr>
 
 
            <tr>
                <td>주소</td>
                <td><input type="text" name="address1" id="sample6_address"
                    readonly></td>
            </tr>
 
 
            <tr>
                <td>주소상세</td>
                <td><input type="text" name="address2" id="sample6_address2"></td>
            </tr>
 
 
            <tr>
 
                <td align="center" colspan="2"><input type="button"
                    value="회원가입" id="btnJoin"> <input type="reset" value="취소">
 
                </td>
            </tr>
 
        </table>
    </form>
 
</body>
</html>
cs