관리 메뉴

moozi

javascript 주민번호 regular expression 본문

TIS_2020/빅데이터2020_1기

javascript 주민번호 regular expression

moozi 2020. 10. 22. 11:21

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Regular Expression</title>

    <script>

        var targetStr = "bcabcAB";//원본

        var strReg = /AB/;        //검색패턴

 

        //var strUsingFlag = /AB/i; //대소문자구분없음

        var strUsingFlag = new RegExp("AB""i");

        console.log(targetStr.search(strReg));       // 5

        console.log(targetStr.search(strUsingFlag)); // 2 

        function check(){

            //email정규식

            // var emailRule = /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/i;

 

            // if(!emailRule.test(document.form1.email.value)) {            

            //     alert("email형식에 맞게 입력하세요");

            //     return false;

            // }

            //주민번호정규식

            var juminRule=/^(?:[0-9]{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[1,2][0-9]|3[0,1]))-[1-4][0-9]{6}$/;

            if(!juminRule.test(document.form1.jumin.value)) {            

                alert("주민등록번호 형식에 맞게 입력하세요");

                return false;

            }

        }

    </script>

</head>

<body>

    <form name="form1" action="join.jsp" method="post" onSubmit="return check();">

        <input id="email" type="text" name="email" placeholder="email">

        <input id="jumin" type="text" name="jumin" placeholder="주민등록번호">

        <input type="submit" value="등록">

    </form>

</body>

</html>

'TIS_2020 > 빅데이터2020_1기' 카테고리의 다른 글

10/22 layout06  (0) 2020.10.22
jquery layout  (0) 2020.10.22
javascript 주민번호 regular expression  (0) 2020.10.22
10/21 join.html  (0) 2020.10.21
포트폴리오 url  (15) 2020.10.20
10/19 kakao  (0) 2020.10.19
0 Comments
댓글쓰기 폼