Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

jquery masked input plugin formatting

Hi experts,
In my asp.net mvc5 , C# , razor application I'm using this jQuery masked input plugin.

http://digitalbush.com/projects/masked-input-plugin/

So on my view inside the jquery document ready section my code looks like this:

    <script type="text/javascript">
        $(document).ready(function () {
        // ------------------------------------


                    $('#SSNtextbox').val('');
                    $('#SSNtextbox').unmask('')
                    $('#SSNtextbox').attr('placeholder', '###-##-####');
                    //  Social Security Number formatting
                    $('#SSNtextbox').mask('999-99-9999');


        // ------------------------------------
        });
    </script>

So on my page i have a text box that looks like this

 @Html.TextBoxFor(model => model.EmployeeSSN, new { id = "SSNtextbox", @class = "SSNText", @placeholder = "" })

The masking works just fine on my textbox.

When I run my page the place holder in my textbox looks like this which is what I want:

User generated image
So then when i click in the text box and start typing the masking works just fine and looks like this:

User generated image
This textbox is part of a form.

When I click the submit button though I noticed that this textbox is passing the social i entered along with the masking. In visual studio debugging the data that shows that its passing looks like this:

User generated image
Anyone know how to pass only the numbers I typed in (without the masking)?

So instead of passing this, like it's doing now:   123-45-6789

The value my form should submit should be only this: 123456789
Avatar of maqskywalker
maqskywalker

ASKER

Here is a fiddle of my example:

If you notice after I click the button the formatted data is shown on my page.

https://jsfiddle.net/sz8Laaoq/

How do I only display the number I typed in on my page, without the masking?
ASKER CERTIFIED SOLUTION
Avatar of David S.
David S.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial