As far as I understood, your question is how to do the following:
Mask input field
Input field can only accept number
So I do the following steps:
Make input field as password
type.
Detect the key in character while typing(keypress
is done before value change), then don't change the existing value when the character is not numeric.
I added a button that you can click it to show current value.
$('#in').keypress(function(event){
var reg = /[0-9]/g;
var key = String.fromCharCode(event.keyCode);
if(!reg.test(key))
return false;
})
$('#show').click(function(event){
alert($('#in').val());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="in" type="password"/>
<br />
<button id="show">Show Value</button>
Update
Below is an example done by this plugin.
This may meet your requirement.
$('#inputtext').securenumbermask({mask:'_',maxlength:15});
$('#show').click(function(event){
alert($('#inputtext-original').val());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.jqueryscript.net/demo/jQuery-Plugin-To-Mask-Numbers-In-Text-Field-Secure-Number-Mask/js/securenumbermask.js">
</script>
<input class="form-control" type="text" id="inputtext" value="123" input-original="inputtext-original">
<input id="inputtext-original" type="hidden" value="**">
<br />
<button id="show">Show Value</button>