jquery masked input make first two digits as non-e

2020-07-30 03:55发布

问题:

Hi I'm currently using the jquery masked input and I want to make the first two digits as permanent numbers. For example, I have a number like (09)191-234-567

(09) are permanent mask while the following 9 digits are editable.

IF I do this, $("#phone").mask("(99) 999-999-999"); all digits are editable. I tried searching but found no luck.

Thanks in advance.

回答1:

The maskedinput plugin (which I believe you're referring to) allows you to define your own masks.

This means you can add your own masking character for numbers (#, for example), and remove the masking definition for 9 so that it no longer does anything.

$.mask.definitions['#'] = $.mask.definitions['9'];  //Set # to do what 9 does
$.mask.definitions['9'] = null;                     //Remove 9 as a masking character
$("input").mask("(09) ###-###-###");
<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.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<input type="text">