I am using a html input type='number' field to set PIN no (no characters are allowed) but I want the characters to be masked as I type.
I am new in web development. Please help me out.
I am using a html input type='number' field to set PIN no (no characters are allowed) but I want the characters to be masked as I type.
I am new in web development. Please help me out.
You can use like this-
<input type="password" pattern="[0-9]*" inputmode="numeric">
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password#Setting_length_requirements
I think this helps if you want to make input type='password' accept only numbers
Solution with jQuery
$(function () {
$('#pincode').bind('keyup paste', function () {
this.value = this.value.replace(/[^0-9]/g, '');
});
$('#pincode').keyup(function () {
var text = $(this).val().trim();
$('#errorname').text(text);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form action="" method="post" id="sign_in_form">
<div class="form-group">
<label for="email" style="font-weight: bold; cursor: text;"><span style="color:red;">* </span>Enter PIN</label>
<input type="password" name="pincode" id="pincode" maxlength="6" inputmode="numeric">
</div>
<div id="errorname"></div>
</form>