jquery masked input plugin set value digits

大城市里の小女人 提交于 2019-12-12 02:38:27

问题


$(".id").mask("999-99-9999-999-99");

I have the above mask input format i want to know if it is possible to have a predefined value for x number of characters like for example

I want the first 5 letters to have a default and unchangeable numbers.

Sample number will be

639-27-9999-999-99

here the numbers 639-27- should be always there meaning when the input has focus it will automatically be put there and cannot be changed.

F.Y.I

Plugin


回答1:


A workaround solution might be,

$.mask.definitions["9"] = null;
$.mask.definitions["^"] = "[0-9]";
$(".id").mask("639-27-^^^-^^^-^^");
  1. remove the definition for 9
  2. add a definition for numeric regex with a new key ex. ^
  3. use the new definition

fiddle

hope this helps




回答2:


You can do it like this using the plugin: $(".id").mask("639-27-9999-999-99"); As they used 9 as their number definition, you can change it in their source code with any other character.



来源:https://stackoverflow.com/questions/29862088/jquery-masked-input-plugin-set-value-digits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!