웹프로그래밍

Global It Leader!!


jQuery


 
 

비밀번호 작성 규칙 검사 스크립트

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 3,283회 작성일 16-12-21 19:16

본문

<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset="utf-8" />
<title>New Document</title>
<script>
    function passwordCheck() {
       
        var userID = document.getElementById("userID").value;
        var password = document.getElementById("password").value;
        var newPassword1 = document.getElementById("newPassword1").value;
        var newPassword2 = document.getElementById("newPassword2").value;
       
        // 재입력 일치 여부
        if (newPassword1 != newPassword2) {
            alert("입력한 두 개의 비밀번호가 서로  일치하지 않습니다.");
            return false;
        }
       
        // 길이
        if(!/^[a-zA-Z0-9!@#$%^&*()?_~]{6,15}$/.test(newPassword1))
        {
            alert("비밀번호는 숫자, 영문, 특수문자 조합으로 6~15자리를 사용해야 합니다.");
            return false;
        }
       
        // 영문, 숫자, 특수문자 2종 이상 혼용
        var chk = 0;
        if(newPassword1.search(/[0-9]/g) != -1 ) chk ++;
        if(newPassword1.search(/[a-z]/ig)  != -1 ) chk ++;
        if(newPassword1.search(/[!@#$%^&*()?_~]/g)  != -1  ) chk ++;
        if(chk < 2)
        {
            alert("비밀번호는 숫자, 영문, 특수문자를 두가지이상 혼용하여야 합니다.");
            return false;
        }
       
        // 동일한 문자/숫자 4이상, 연속된 문자
        if(/(\w)\1\1\1/.test(newPassword1) || isContinuedValue(newPassword1))
        {
            alert("비밀번호에 4자 이상의 연속 또는 반복 문자 및 숫자를 사용하실 수 없습니다.");
            return false;
        }
       
        // 아이디 포함 여부
        if(newPassword1.search(userID)>-1)
        {
            alert("ID가 포함된 비밀번호는 사용하실 수 없습니다.");
            return false;
        }
       
        // 기존 비밀번호와 새 비밀번호 일치 여부
        if (password == newPassword2) {
            alert("기존 비밀본호와 새 비밀번호가 일치합니다.");
            return false;
        }
       
        alert("테스트 통과!");
       
    }
   
    function isContinuedValue(value) {
        console.log("value = " + value);
        var intCnt1 = 0;
        var intCnt2 = 0;
        var temp0 = "";
        var temp1 = "";
        var temp2 = "";
        var temp3 = "";
 
        for (var i = 0; i < value.length-3; i++) {
            console.log("=========================");
            temp0 = value.charAt(i);
            temp1 = value.charAt(i + 1);
            temp2 = value.charAt(i + 2);
            temp3 = value.charAt(i + 3);
 
            console.log(temp0)
            console.log(temp1)
            console.log(temp2)
            console.log(temp3)
 
            if (temp0.charCodeAt(0) - temp1.charCodeAt(0) == 1
                    && temp1.charCodeAt(0) - temp2.charCodeAt(0) == 1
                    && temp2.charCodeAt(0) - temp3.charCodeAt(0) == 1) {
                intCnt1 = intCnt1 + 1;
            }
 
            if (temp0.charCodeAt(0) - temp1.charCodeAt(0) == -1
                    && temp1.charCodeAt(0) - temp2.charCodeAt(0) == -1
                    && temp2.charCodeAt(0) - temp3.charCodeAt(0) == -1) {
                intCnt2 = intCnt2 + 1;
            }
            console.log("=========================");
        }
 
        console.log(intCnt1 > 0 || intCnt2 > 0);
        return (intCnt1 > 0 || intCnt2 > 0);
    }
</script>
</head>
 
<body>
    id : <input id="userID" type="text" value="abcd"/><br/>
    password : <input id="password" type="text" value="abcd"/><br/>
    newPassword : <input id="newPassword1" type="text" value="abcd"/><br/>
    newPassword : <input id="newPassword2" type="text" value="abcd"/><br/>
    <button onclick="passwordCheck()">Click</button>
</body>
</html>

댓글목록

등록된 댓글이 없습니다.

전체 142
게시물 검색
jQuery 목록
번호 제목 글쓴이 조회 날짜
42 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3258 04-04
41 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3247 01-12
40 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3230 02-23
39 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3209 11-03
38 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3206 12-27
37 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3176 04-23
36 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3155 09-05
35 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3033 03-06
34 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3008 09-23
33 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2984 02-04
32 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2911 02-04
31 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2844 03-02
30 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2790 01-20
29 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2727 10-06
28 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2721 01-30
27 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2706 08-18
26 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2662 03-26
25 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2632 11-06
24 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2591 10-28
23 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2578 09-11