How can I mask string from input field as soon as it is entered by the user? I would like to always show a start if the the length of the entered string exceeds the length of 8 characters. For example
12 2458 ************************
The total number of stars and remaining characters should match the entire user-entered string.
But from my code I get something like this:
12 2458 *
I would like to have a starred string in one field (hidden input) and store the string in the other field which will be saved in the database without stars.
<input type="text" name="id_account_shown" class="form-control" placeholder="Enter your account number..." required id="id_account_shown">
<!-- Call functions each time the value of the input field changes -->
<script>
$("#id_account_shown").on("input", function() {
var accountnumber = document.getElementById('id_account_shown').value; // form value
var star = '*';
var accountnumber_short = accountnumber.substring(0, 8);
if (accountnumber.length > 8) {
document.getElementById('id_account_shown').value = accountnumber_short + star; // change data
}
});
</script>