How to get the jQuery MaskedInput unmask() function to work properly?

梦想与她 提交于 2019-12-03 06:19:52

You don't need to pass a parameter to the unmask function! Use it without a parameter and it works well.

$("#OfficePhone").unmask();

I was able to figure out the code to get it to work. Below is the code I am using now.

<script type="text/javascript">
$(function($) {
  $("#OfficePhone").mask("(999) 999-9999? x99999");
  $("#InternationalOfficePhone").click(function() {
    var mask = "(999) 999-9999? x99999";
    if ($("#InternationalOfficePhone").is(':checked')) {
      $("#OfficePhone").unmask(mask);
    } else {
      $("#OfficePhone").mask(mask);
    }
  });
});
</script>

I run through the same problem, and what helped me is:

    var maskedInput = $("#id").data('mask');
    if (maskedInput) {
        maskedInput.remove();
    }

Try using the :checked instead of attr check, I think that is the problem. I mean use $('#InternationalOfficePhone').is(':checked') in the if condition.

Remove the inputmask:

$(selector).inputmask('remove');

or

var input = document.getElementById(selector);
if (input.inputmask)
  input.inputmask.remove()

or

Inputmask.remove(document.getElementById(selector));

I am using query.maskedinput.js Version: 1.4.1 I referred https://github.com/digitalBush/jquery.maskedinput/blob/bb66bf9b1c3eddd1d2349cee103127ae08d0a877/demo/index.html

the unmasking is done by $("input").blur(function() { $("#info").html("Unmasked value: " + $(this).mask());

example Masking is

$("#pannumber").mask("aaaaa 9999 a");

Unmasking

$("#pannumber").blur(function() {

var pannumber= $(this).mask() ;

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