티스토리 뷰

유효성 검사는 jsp 뷰단에서 자바스크립트로만 했었는데 Ajax로 한단어 한단어 체크하여 패스워드 유효화 체크를 한번 구현해 봄.

 

참고 : https://xxxelppa.tistory.com/56

        http://sunkyun.com/community/bbs/board.php?bo_table=script&wr_id=13

        https://hongku.tistory.com/249

        https://sgroom.tistory.com/112

@RequestMapping(value = "/pwCheck", method = RequestMethod.POST)
	@ResponseBody
	public boolean PwCheck(String pw) {		
		logger.info("PwCheck");		
		
		boolean check = false;	

		String pw_chk = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[$@$!%*?&`~'\"+=])[A-Za-z[0-9]$@$!%*?&`~'\"+=]{6,18}$";
				
		Pattern pattern_symbol = Pattern.compile(pw_chk);		
		Matcher matcher_symbol = pattern_symbol.matcher(pw);		
		
		if(matcher_symbol.find()) {	
			check = true;
		}		
		return check;
	}
$(document).ready(function(){
	$('#pw1').keyup(function(){
		$('#pwCheckFF').text('');
	}); 
	
	$('#repw1').keyup(function(){
		if($('#pw1').val()!=$('#repw1').val()){
			$('#pwCheckFF').text('');
	  		$('#pwCheckFF').html("패스워드 확인이 불일치 합니다");
	 	}else{
		  	$('#pwCheckFF').text('');
		  	$('#pwCheckFF').html("<font color='#70AD47'>패스워드 확인이 일치 합니다.</font>");
	 	}
	});
 }); 
 
 //비밀번호 실시간 유효성 체크
function pwCheck(pw){
	$.ajax({
		type:"POST",
		url: "/pwCheck",
		data : { pw: pw },
		success:function(result){	
			if(result == true){				
				pwCheckF.innerHTML = "유효성 체크 문제 없음"; 				
			}else{				
				pwCheckF.innerHTML = "유효성 체크 범위 벗어남"; 
			}
		},
    	error:function(request,status){
    		alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
    	}
	});	
	
}

 

<input type="password" class="join" name="pw" id="pw1" oninput="pwCheck(pw1.value)" tabindex="2" placeholder="비밀번호" />
<input type="password" class="join" name="repw" id="repw1" tabindex="3" placeholder="비밀번호 확인"/>
<p id="pwCheckF" style="color: #FF6600; margin: 0;"></p>
<p id="pwCheckFF" style="color: #FF6600; margin: 0;"></p>

'JAVA' 카테고리의 다른 글

맥북 M1 JAVA 설정  (0) 2022.03.15
String 타입으로 받아온 날짜 하루 더하기  (0) 2018.04.24
키워드 Return이 지니닌 2가지 의미  (0) 2015.07.11
값을 반환하는 메소드  (0) 2015.07.11
메소드와 변수의 스코프  (0) 2015.07.11
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/02   »
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
글 보관함