asp.netjquery-inputmask

JQuery input mask in asp.net


I have an asp:button on my web page. Can I apply JQuery input mask on my asp.net button. Below is what I did:

I installed

Install-Package jQuery.InputMask -Version 5.0.2

I have this on my page in Head tag:

<script src="Scripts/inputmask/inputmask.js"></script>  

On my web page, I have Phone number field:

<asp:TextBox ID="txtPhonenumber" runat="server" placeholder="(XXX) XXX-XXXX"></asp:TextBox>

I want to apply input mask of phone number on my webform if possible.


Solution

  • <asp:TextBox ID="txtPhonenumber" runat="server"></asp:TextBox>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#<%= txtPhonenumber.ClientID %>").mask("(999) 9999-9999?9");
                });
      </script>
    

    Output here:

    enter image description here