if your output is acceptable on other field, this might be useful
$("#input").on("keyup", function() {
var input = $(this).val().split("")
var res = $.map(input, (el, ix) => {
return ix < 2 || ix > input.length - 3? el:"*"
})
$("#output").html(res.join(""));
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="password" id="input" />
<br><span id="output"></span>
1
solved Masking inputs any field and values