웹프로그래밍

Global It Leader!!


jQuery


 
 

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

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 3,309회 작성일 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 목록
번호 제목 글쓴이 조회 날짜
122 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1865 08-04
121 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2149 06-25
120 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1896 05-28
119 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3073 03-06
118 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2881 03-02
117 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2658 11-06
116 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3240 11-03
115 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2640 10-28
114 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2754 10-06
113 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2607 09-11
112 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2810 01-20
111 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2727 08-18
110 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2742 01-30
109 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3036 09-23
108 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2936 02-04
107 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3002 02-04
106 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3183 09-05
105 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3256 02-23
104 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3232 12-27
열람중 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3310 12-21