Reputation: 541
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>
Upvotes: 4
Views: 6599
Reputation: 1
In masked.input.min.js
file find:
translation:{
0: {
pattern: /\d/
},
"#": {
pattern: /\d/,
recursive: !0
},
A: {
pattern: /[a-zA-Z0-9]/
}
}
this part and delete:
9: {
...
}
Upvotes: 0
Reputation: 4527
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"
});
Upvotes: 4
Reputation: 1909
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>
Upvotes: 6