본문 바로가기
JS

JavaScript - 비밀번호 유효성 검사 (회원가입)

by 나는 코딩왕 2021. 2. 18.

JavaScript 비밀번호 유효성 검사하기~~!!

 

 

JavaScript 부분

<script language="javascript">
	function checkIt(){
		if (userinput.pw.value != userinput.checkpw.value) {
			alert("비밀번호가 일치하지 않습니다");
			return false;
		}
		if(userinput.pw.value.length <8 || userinput.pw.value.length > 12){
			alert("비밀번호를 8~12자 사이로 입력하세요");
			return false;
		}
        
</script>

사용자가 입력한 부분 중 id가 'pw'인 값을 받아 체크하여 alert창 이벤트 처리

 

body 부분

<h2>회원가입</h2>
		
	<table class="type11">
		<tr>
			<th>아이디</th>
			<td><input type="text" name="id" >
				<input type="button" value="아이디 중복확인"
				Onclick="openConfirmid(this.form)"></td>
		</tr>
        	<tr>
			<th class>비밀번호</th>
			<td><input type="password" name="pw" id ="pw" placeholder="8~12사이로 입력하세요." required></td>
		</tr>
    	</table>    

댓글