Input mask MVC unmask in controller

4.9k Views Asked by At

Im working in MVC 5.2 .NET 4.5:

Can anyone point me to a js or other library / method for an input mask that will unmask and just send the entered data in the view model to the controller?

Any .js library I've tried so far that can unmask, still sends the mask to the controller.

Thank you.

1

There are 1 best solutions below

0
On BEST ANSWER

https://github.com/RobinHerbots/jquery.inputmask

Set autoUnmask to true for client side validation and removeMaskOnSubmit to true to get the input with the literals removed in the server side validation or controller.

Example of an editor template using this for a phone number:

@model string

@Html.TextBox("", Model, new { @class = "form-control" })

<script type="text/javascript">

$(function () {
    $('#@Html.IdForModel()').inputmask({ "mask": "(999) 999-9999", 'autoUnmask': true, 'removeMaskOnSubmit': true });
});
</script>