<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>회원 가입 페이지 실습</title>
<!-- css 파일을 불러오는 코드 -->
<!-- 아이콘 사용을 위한 Font Awesome 6 CDN -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<!-- 구글 웹 폰트 사용을 위한 CDN -->
<!-- 내가 만든 CSS 파일-->
<link rel="stylesheet" type="text/css" href="./css/reset.css">
<link rel="stylesheet" type="text/css" href="./css/commons.css">
<link rel="stylesheet" type="text/css" href="./css/test.css">
<style>
</style>
<!-- javascript 작성 공간 -->
<script>
$(function(){
//상태 객체
var status = {
memberId:false,
memberPw:false,
memberPwCheck:false,
memberNickname:false,
memberContact:false,
memberBirth:false,
memberEmail:false,
memberAddress:false,
ok:function(){
return this.memberId && this.memberPw
&& this.memberPwCheck && this.memberNickname
&& this.memberContact && this.memberBirth
&& this.memberEmail && this.memberAddress;
},
};
$("[name=memberId]").blur(function(){
var regex = /^[a-z][a-z0-9]{4,19}$/;
var isValid = regex.test($(this).val());
$(this).removeClass("success fail");
$(this).addClass(isValid ? "success" : "fail");
status.memberId = isValid;
});
$("[name=memberPw]").blur(function(){
var regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$])[A-Za-z0-9!@#$]{8,16}$/;
var isValid = regex.test($(this).val());
$(this).removeClass("success fail");
$(this).addClass(isValid ? "success" : "fail");
status.memberPw = isValid;
});
$("#password-check").blur(function(){
var pw1 = $("[name=memberPw]").val();
var pw2 = $(this).val();
$(this).removeClass("success fail fail2");
if(pw1.length == 0) {
$(this).addClass("fail2");
status.memberPwCheck = false;
}
else if(pw1 == pw2) {
$(this).addClass("success");
status.memberPwCheck = true;
}
else {
$(this).addClass("fail");
status.memberPwCheck = false;
}
});
$("[name=memberNickname]").blur(function(){
var regex = /^[ㄱ-ㅎㅏ-ㅣ가-힣0-9]{2,10}$/;
var isValid = regex.test($(this).val());
$(this).removeClass("success fail");
$(this).addClass(isValid ? "success" : "fail");
status.memberNickname = isValid;
});
$("[name=memberEmail]").blur(function(){
var regex = /^[a-zA-Z0-9+-\_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
var email = $(this).val();
var isValid = email.length == 0 || regex.test(email);
$(this).removeClass("success fail");
$(this).addClass(isValid ? "success" : "fail");
status.memberEmail = isValid;
});
$("[name=memberContact]").blur(function(){
var regex = /^010[1-9][0-9]{7}$/;
var contact = $(this).val();
var isValid = contact.length == 0 || regex.test(contact);
$(this).removeClass("success fail");
$(this).addClass(isValid ? "success" : "fail");
status.memberContact = isValid;
});
$("[name=memberBirth]").blur(function(){
var regex = /^(19[0-9]{2}|20[0-9]{2})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
var birth = $(this).val();
var isValid = birth.length == 0 || regex.test(birth);
$(this).removeClass("success fail");
$(this).addClass(isValid ? "success" : "fail");
status.memberBirth = isValid;
});
$("[name=memberPost],[name=memberAddr1],[name=memberAddr2]").blur(function(){
//this 사용 불가(확실히 누군지 알 수 없음)
var post = $("[name=memberPost]").val();
var addr1 = $("[name=memberAddr1]").val();
var addr2 = $("[name=memberAddr2]").val();
var isBlank = post.length == 0 && addr1.length == 0 && addr2.length == 0;
var isFill = post.length > 0 && addr1.length > 0 && addr2.length > 0;
var isValid = isBlank || isFill;
$("[name=memberPost],[name=memberAddr1],[name=memberAddr2]").removeClass("success fail");
$("[name=memberPost],[name=memberAddr1],[name=memberAddr2]").addClass(isValid ? "success" : "fail");
status.memberAddress = isValid;
});
$(".join-form").submit(function(e){
$(".form-input").blur();
if(!status.ok()) {
e.preventDefault();
//return false;
}
});
});
</script>
</head>
<body>
<form class="join-form" action="" method="post" autocomplete="off">
<div class="container w-600">
<div class="row">
<h1>회원 정보 입력</h1>
</div>
<div class="row left">
<label>아이디 <i class="fa-solid fa-asterisk red"></i></label>
<input type="text" name="memberId" placeholder="영문 소문자, 숫자 5~20자"
class="form-input w-100">
<div class="success-feedback">멋진 아이디입니다!</div>
<div class="fail-feedback">아이디를 형식에 맞게 입력하세요</div>
<div class="fail2-feedback">이미 사용중인 아이디입니다</div>
</div>
<div class="row left">
<label>비밀번호 <i class="fa-solid fa-asterisk red"></i></label>
<input type="password" name="memberPw"
placeholder="영문,숫자,특수문자 반드시 1개 이상 포함"
class="form-input w-100">
<div class="success-feedback">올바른 비밀번호 형식입니다</div>
<div class="fail-feedback">잘못된 비밀번호 형식입니다</div>
</div>
<div class="row left">
<label>비밀번호 확인 <i class="fa-solid fa-asterisk red"></i></label>
<input type="password" id="password-check"
placeholder="비밀번호 한 번 더 입력" class="form-input w-100">
<div class="success-feedback">비밀번호가 일치합니다</div>
<div class="fail-feedback">비밀번호가 일치하지 않습니다</div>
<div class="fail2-feedback">비밀번호를 먼저 작성하세요</div>
</div>
<div class="row left">
<label>닉네임</label>
<input type="text" name="memberNickname"
placeholder="한글 또는 숫자 2~10자" class="form-input w-100">
<div class="success-feedback">멋진 닉네임입니다!</div>
<div class="fail-feedback">닉네임 형식이 올바르지 않습니다</div>
<div class="fail2-feedback">닉네임이 이미 사용중입니다</div>
</div>
<div class="row left">
<label>이메일</label>
<input type="text" name="memberEmail"
placeholder="test@kh.com" class="form-input w-100">
<div class="fail-feedback">이메일 형식이 잘못되었습니다</div>
</div>
<div class="row left">
<label>연락처</label>
<input type="tel" name="memberContact" placeholder="010XXXXXXXX (- 없이)"
class="form-input w-100">
<div class="fail-feedback">전화번호 형식이 올바르지 않습니다</div>
</div>
<div class="row left">
<label>생년월일</label>
<input type="date" name="memberBirth" class="form-input w-100">
<div class="fail-feedback">잘못된 날짜를 선택하셨습니다</div>
</div>
<div class="row left">
<label style="display: block;">주소</label>
<input type="text" name="memberPost" placeholder="우편번호"
class="form-input" size="6" maxlength="6">
<button type="button" class="btn">
<i class="fa-solid fa-magnifying-glass"></i>
</button>
<input type="text" name="memberAddr1" placeholder="기본주소"
class="form-input w-100 mt-10">
<input type="text" name="memberAddr2" placeholder="상세주소"
class="form-input w-100 mt-10">
<div class="fail-feedback">모든 주소를 작성해주세요</div>
</div>
<div class="row left">
<button type="submit" class="btn btn-positive w-100">가입하기</button>
</div>
</div>
</form>
</body>
</html>