HTML 패널

회원가입 폼

JavaScript 패널 document.getElementById('signupForm').addEventListener('submit', function(e) { e.preventDefault(); // 폼 제출 방지 // 에러 메시지 초기화 document.querySelectorAll('.error').forEach(e => e.textContent = ''); let isValid = true; // 아이디 검증 (4자 이상) let username = document.getElementById('username').value; if (username.length < 4) { document.getElementById('usernameError').textContent = '아이디는 4자 이상이어야 합니다'; isValid = false; } // 비밀번호 검증 (8자 이상) let password = document.getElementById('password').value; if (password.length < 8) { document.getElementById('passwordError').textContent = '비밀번호는 8자 이상이어야 합니다'; isValid = false; } // 비밀번호 확인 let passwordConfirm = document.getElementById('passwordConfirm').value; if (password !== passwordConfirm) { document.getElementById('confirmError').textContent = '비밀번호가 일치하지 않습니다'; isValid = false; } // 이메일 검증 let email = document.getElementById('email').value; if (!email.includes('@')) { document.getElementById('emailError').textContent = '올바른 이메일 형식이 아닙니다'; isValid = false; } // 모든 검증 통과 if (isValid) { document.getElementById('result').textContent = '✅ 회원가입 성공!'; document.getElementById('result').style.color = 'green'; } }); CSS 패널 body { font-family: Arial, sans-serif; max-width: 400px; margin: 50px auto; padding: 20px; } form div { margin-bottom: 15px; } label { display: inline-block; width: 120px; font-weight: bold; } input { padding: 8px; width: 200px; border: 1px solid #ddd; } input:focus { border-color: #3498db; outline: none; } .error { display: block; color: red; font-size: 12px; margin-left: 120px; margin-top: 5px; } button { margin-left: 120px; padding: 10px 30px; background-color: #2ecc71; color: white; border: none; cursor: pointer; font-size: 16px; } button:hover { background-color: #27ae60; } #result { margin-top: 20px; font-size: 18px; font-weight: bold; text-align: center; }