본문 바로가기
Coding/JavaScript

[JavaScript & jQuery] 자바스크립트로 주민번호 뒷자리 마스킹 하는 방법 !!(별표처리)

by 포스트it 2023. 3. 15.
728x90
반응형

[JavaScript & jQuery] 자바스크립트로 주민번호 뒷자리 마스킹 하는 방법 !!(별표처리)

아래 코드 사용하시면 주민번호 뒷자리 첫번째 제외하고 마스킹(별표처리) 하실 수 있습니다 :)

예제코드
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <script  src="https://code.jquery.com/jquery-3.3.1.js"  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="  crossorigin="anonymous"></script>
        <title>test</title>
    </head>
    
    <body>
        <h1>주민번호 뒷자리 마스킹</h1>
        <input type="tel" id="jumin1" name="inputValue" maxlength="6"> - <input type="input" id="jumin2" maxlength="7">
    </body>
</html>
<script>

$("#jumin1").on('keypress', function(){
    var text = $('#jumin1').val().replace(/[^0-9]/g,"");
    if(text.length >= $(this).attr("maxlength")){
        $("#jumin2").focus();
        return;
    }
});

$("#jumin2").on('keypress', function(e){
    var inVal = String.fromCharCode(e.which);
    }).on('input',function(e){
        $(this).val($(this).val().replace(/(?<=.{1})./gi, "*"));
    });

</script>
728x90
반응형

댓글