Rick
Rick

Reputation: 541

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>

Upvotes: 4

Views: 6599

Answers (3)

Azik Nabiyev
Azik Nabiyev

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

Alexander
Alexander

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

Jeric Cruz
Jeric Cruz

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

Related Questions