How to mask input with Jquery in MVC5?

OfficalMesut picture OfficalMesut · Jun 17, 2016 · Viewed 11.8k times · Source

Last days, I try to develop MVC web application in .Net Framework. I try to mask input on form . I have download Jquery masked input and I wrote that code in my view section.

@section Scripts{
    <script type="text/javascript" src="/Scripts/jquery.maskedinput.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-1.8.3.min.js"  charset="utf-8"></script>

    <script type="text/javascript">
        $(function () {
            $("#phone").mask("(999) 999-9999");
        });
    </script>
}

I try to mask textbox like that :

@Html.TextBoxFor(model => model.PhoneNumber, new { htmlAttributes = new { @class = "form-control" ,@id="phone"} })

But It does not work. Where is the wrong ?

I try few ways to mask it but I did not succeed. Could any one help me?

Answer

HudsonPH picture HudsonPH · Jun 17, 2016

Is very simple, change the script order

<script type="text/javascript" src="/Scripts/jquery-1.8.3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/Scripts/jquery.maskedinput.min.js"></script>