views:

37

answers:

3

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?

+1  A: 
customerPhone = new string(customerPhone.ToCharArray()
                             .Where(c => char.IsDigit(c)).ToArray());
JanW
A: 

You can strip out non-numeric characters with Regular Expressions in .NET, like this:

customerPhone = Regex.Replace(customerPhone, "[^0-9]", "");
ChessWhiz
A: 

What I'm doing right now is, using the submitHandler (Validation plugin) to reset the input value, like this:

submitHandler: function(form) {
    $("#txtPhone").val($("#txtPhone").mask());
    form.submit();
},

This solves the problem BUT smells really bad...

BrunoSalvino