Search code examples
c#asp.netjquerymaskedinput

How to remove literals from input mask after form submit?


I'm using Josh Bush's MaskedInput plugin for jQuery in an ASP.NET 3.5 Webform app.

How to get rid from the literals in the code-behind file after form submit?

E.g: a phone input with the mask $("#txtPhone").mask("(99)9999-9999");

In the code-behind:

string customerPhone = txtPhone.Text

Which returns me: (12)3456-7890

But this is what I want: 1234567890

In the plugins changelog page it says I can use mask() method with no arguments to archieve this. But how to do it from the code-behind?!

EDIT

My question wasn't clear, so: I want to send to the server the unmasked value. How to do that?


Solution

  • Set removeMaskOnSubmit as true when you initialize the inputmask

        $("#txtPhone").inputmask({removeMaskOnSubmit: true});
    

    Or we can get the unmasked value using this

    $("#txtPhone").inputmask('unmaskedvalue');