Format TextBox using Inputmask plugin in jQuery

Last Reply 5 months ago By dharmendr

Posted 5 months ago

hello,

i have a textbox in which i want take int from user in this format

000-000-0000

so as user type in int values its automatically become in this format

 

please advice

Posted 5 months ago

Hi nauna,

Check the below example.

HTML

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/inputmask/inputmask.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.3.4/inputmask/inputmask.extensions.min.js"></script>
<script type="text/javascript">
    $(function () {
        var inputmask = new Inputmask("###-###-####");
        inputmask.mask($('[id*=txtData]'));
    });
</script>
<input id="txtData" name="txtData" type="text" maxlength="12" />

Demo