inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

프로그래밍 시작하기 : 웹 입문 (Inflearn Original)

실습: 회원가입 폼 검증하기 - 2 (3-21)

비밀번호 동일 validation 구현이 잘 안됩니다!

499

Minkyung K

작성한 질문수 5

0

안녕하세요. 비밀번호를 동일하게 입력했는데 계속 validation error message 가 표시됩니다. 왜 그런걸까요? @@

--- 아래는 작성한 js code 첨부합니다 ---

window.addEventListener('load', function() {
	// alert('load 완료')
	clearMessages();
 
	var formElem = document.querySelector('form');
	formElem.onsubmit = submitForm;
});


function clearMessages() {
	var messages = document.getElementsByClassName('alert-message')
	for (var i = 0; i < messages.length; i++) {
		messages[i].style.display = 'none';
	}
}

function showMessage(inputElement, message) {
	var messageElem = inputElement.parentNode.querySelector('span');
	messageElem.style.display = 'inline';
	messageElem.innerText = message;
	inputElement.focus();
}


function submitForm() {
	// account(계정정보) 가져오기
	var accountInput = document.querySelector('input[name="account"]');
	var passwordInput = document.querySelector('input[name="password"]');
	var passwordConfirmInput = document.querySelector('input[name="password2"]');

	// select, radio, checkbox
	var selectInput = document.querySelector('select[name="birth-month"]');
	var radioInput = document.querySelector('input[name="gender"]:checked');
	var checkInput = document.querySelector('input[name="agree"]');

	console.log(accountInput.value);
	console.log(passwordInput.value);
	console.log(passwordConfirmInput.value);

	console.log(selectInput.value);
	console.log(radioInput.value);
	console.log(checkInput.value);

	var success = true;

	if (accountInput.value.length < 6) {
		showMessage(accountInput, '계정은 6자리 이상이어야합니다.');
		var success = false;
	}

	if (passwordInput.value.length < 10) {
		showMessage(passwordInput, '비밀번호는 10자리 이상이어야 합니다.');
		var success = false;
	}

	if (passwordConfirmInput.value.length !== passwordInput.value) {
		showMessage(passwordConfirmInput, '비밀번호가 동일하지 않습니다.');
		var success = false;
	}

return success;


}

javascript HTML/CSS

답변 1

2

임찬

if (passwordConfirmInput.value.length !== passwordInput.value) {
		showMessage(passwordConfirmInput, '비밀번호가 동일하지 않습니다.');
		var success = false;
	}

length 하고 value를 비교해서 그런 것 같습니다.

unregistered 이라 뜨며 작동하지 않습니다.

0

51

1

공부한 내용을 블로그에 정리해서 올려도되나요?

0

95

1

sublime text 설치 불가

0

177

1

사진과 본문 내용에 패딩이 40px 들어가 있는데 이유를 모르겠습니다

0

99

1

처음 질문과 옵션 관련 질문입니다.

0

90

1

마지막에 news 관련 질문

0

83

1

태그 닫는 단축키가 뭔가요?

0

170

1

강의에 사용하는 예제 코드 자료 있나요?

0

385

1

회원가입 폼 검증하기 실행이 안됩니다.

0

274

1

이미지랑 아이콘 파일을 어떻게 찾아요?

0

352

1

VS 코드는 절대 경로랑 상대 경로로 상위 문서 접근이 차단되어 있네요

0

476

0

프로젝트 고민 해결이 안되어 다시 올립니다.

0

394

1

프로젝트 고민 다시올립니다.

0

448

1

친구와의 프로젝트 고민

0

421

1

화면 오른쪽 스크롤이 넘어가질 않아요!

0

516

1

학과 설정

0

331

2

회원가입폼 검증 -2 에서 문제가생겼습니다

0

331

1

card.html 버튼 위치

0

602

1

인스타그램 코드 작성 후 동작을 해보았는데 버튼을 눌러도 넘어가질않네요

0

357

2

carousel의 footer부분에

0

295

1

margin 값에 관한 질문입니다.

0

407

1

function clearMessages() 함수의 원리를 알고싶습니다

0

320

1

removeEventListener

0

236

1

버튼을 눌렀을때 케러셀의 이동

0

810

2