투케이2K

356. (javaScript) [validate.js] - 자바스크립트 문법 유효성 검사 라이브러리 사용해 contains 특정 key 값 및 요소 포함 확인 본문

JavaScript

356. (javaScript) [validate.js] - 자바스크립트 문법 유효성 검사 라이브러리 사용해 contains 특정 key 값 및 요소 포함 확인

투케이2K 2024. 3. 7. 08:08
반응형

[개발 환경 설정]

개발 툴 : Edit++

개발 언어 : JavaScript

 

[소스 코드]

    <!-- ===================================================================================================== -->
    <!-- [CDN 주소 설정] -->
    <!-- ===================================================================================================== -->
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/validate.js/0.13.1/validate.min.js"></script>
    <!-- ===================================================================================================== -->






    <!-- ===================================================================================================== -->
    <!-- [자바스크립트 코드 지정] -->
    <!-- ===================================================================================================== -->
    <script>


        // =======================================================================
        // [자바스크립트 라이프 사이클 및 상태 변경 감지 부분]
        // =======================================================================
        window.onload = function() {
            console.log("")
            console.log("==============================================================================")
            console.log("[window onload] : [start]");
            console.log("==============================================================================")
            console.log("")


            /**
             * -------------------------------------------------
             * [요약 설명]
             * -------------------------------------------------
             * window.onload : 브라우저 로드 완료 상태를 나타냅니다 
             * -------------------------------------------------
             * validate.js : 자바스크립트에서 문법 유효성을 검사할 때 사용되는 라이브러리입니다
             * -------------------------------------------------
             * 참고 사이트.  https://validatejs.org/
             * -------------------------------------------------
             * */


            // [contains 포함 확인]
            var check_1 = validate.contains({}, "name"); // json 특정 key 체크
            var check_2 = validate.contains({name: "twok", age: 29}, "name"); // json 특정 key 체크
            var check_3 = validate.contains([], '2k'); // array 요소 포함 체크
            var check_4 = validate.contains(['투케이', '2k'], '2k'); // array 요소 포함 체크


            // [로그 출력 수행]
            console.log("")
            console.log("==============================================================================")
            console.log("[Log] :: [Result]")
            console.log("----------------------------------------------")
            console.log("check_1 : ", check_1)
            console.log("check_2 : ", check_2)
            console.log("check_3 : ", check_3)
            console.log("check_4 : ", check_4)
            console.log("==============================================================================")
            console.log("")


        };


    </script>
 

[결과 출력]

 

 

반응형
Comments