Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Input Mask (Redefine numeric "9")

I'm using RobinHerbots jquery input mask.
How to redefine the "9", so the mask will show XXXX91 instead of XXXXX1?

EDIT: if possible I would like to make last two digits uneditable

var autoPopulateNo = 91  //how to show the mask like this XXXX91

$("#number").inputmask({
"mask": "9999" + autoPopulateNo,
clearMaskOnLostFocus: false,
placeholder:"X",

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
<form action="">  
  <div>
    <label for="number">Mask</label>
    <input id="number" type="text"/>
  </div>
</form>
like image 646
Rick Avatar asked Oct 21 '25 11:10

Rick


2 Answers

You can use "escapeChar"

Definition of the symbols used to escape a part in the mask.

escapeChar: "\\"

var autoPopulateNo = "\\91"  //how to show the mask like this XXXX91

$("#number").inputmask({
"mask": "9999" + autoPopulateNo,
clearMaskOnLostFocus: false,
placeholder:"X",

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
<form action="">  
  <div>
    <label for="number">Mask</label>
    <input id="number" type="text"/>
  </div>
</form>
like image 150
Jeric Cruz Avatar answered Oct 24 '25 03:10

Jeric Cruz


Use placeholder: "XXXX91" instead of placeholder:"X". If you need to escape the 9 in your mask, use \\ symbol:

$("#number").inputmask({ 
  "mask": "9999\\91",
  clearMaskOnLostFocus: false,
  placeholder:"XXXX91"
});
like image 29
Alexander Avatar answered Oct 24 '25 03:10

Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!