Remove literals from input mask after form submit?

后端 未结 7 1069
轮回少年
轮回少年 2020-12-31 03:17

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:

7条回答
  •  庸人自扰
    2020-12-31 04:07

    If you are using the completed callback, then you can just use:

    $(element).mask("(99)9999-9999", {
      completed : function () {
        var numbers = this.val().replace(/()-/g,'');
      }
    }
    

    Otherwise, you can use:

    $(element).val().replace(/()-/g,'');

    If you want to do this before submitting, I suggesting capturing the submit event, using the code immediately above and then submitting the form.

    EDIT: Alex Peattie pointed out the unmask() function, which I must say is a much better solution than mine. I'll leave my answer here, but I'd go with his solution.

提交回复
热议问题