1

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Tanveer Hasan
  • 334
  • 1
  • 5
  • 15

3 Answers3

3

You can use like this-

<input type="password" pattern="[0-9]*" inputmode="numeric">

see details here

Rasel
  • 5,488
  • 3
  • 30
  • 39
1

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

saketh
  • 803
  • 1
  • 10
  • 24
0

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>
Mister Jojo
  • 20,093
  • 6
  • 21
  • 40