How to mask input with Jquery in MVC5?

12,627

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>
Share:
12,627
MesutAtasoy
Author by

MesutAtasoy

Updated on June 04, 2022

Comments

  • MesutAtasoy
    MesutAtasoy almost 2 years

    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?