Remove literals from input mask after form submit?

2019-02-06 04:45发布

this question has already been asked but the solutions where not clear.

Im using Josh Bush's MaskedInput plugin for jQuery

What im trying to achieve is:

E.g: a phone input with the mask

    $("#txtPhone").mask("(99)9999-9999");

EQUALS: (00)9398-8373

i want it to submit : 0093988373

------ Is it possible to remove the .mask on submit but keep the value?

7条回答
等我变得足够好
2楼-- · 2019-02-06 05:15

You can also extract the raw value on a masked input using

$("#YourSelector").data( $.mask.dataName )();

Source : https://github.com/digitalBush/jquery.maskedinput/issues/318


Example
If you use a phone input with such a mask :

$(".phone").mask("99 99 99 99 99")

you can extract the user input using :

$(".phone").data($.mask.dataName)() 
// will produce "0102030405" while the masks displays 01 02 03 04 05
查看更多
何必那么认真
3楼-- · 2019-02-06 05:20

unmask is not a function. This is my way of use. autoUnmask: true

    $('#amount').inputmask('999.999.999.999', {
        numericInput: true,
        autoUnmask: true,
    });
查看更多
Deceive 欺骗
4楼-- · 2019-02-06 05:27

I think you want to use unmask

$("#myForm").submit(function() {
  $("#txtPhone").unmask();
});
查看更多
Viruses.
5楼-- · 2019-02-06 05:29

Set removeMaskOnSubmit as true when you initialize the inputmask

    $("#txtPhone").inputmask({removeMaskOnSubmit: true});
查看更多
何必那么认真
6楼-- · 2019-02-06 05:32

Assuming you have more than just one input being submitted, you could use:

// unmask all inputs, before savinf;
$(FormObj+" input[type=text]").each(function() {
    $(this).unmask();
});

where FormObj is your form object id, such as #form.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-02-06 05:38

Based on Plugin Site:

$("#txtPhone").val($("#txtPhone").mask()); 
查看更多
登录 后发表回答