Mask TextBox: Automatically add hyphen (dash) after two digits in TextBox using jQuery

makumbi
 
on May 27, 2022 06:44 AM
Sample_318937.zip
957 Views

Please help which input mask can i use to impement this input of values in a webpage.

00-39

40-44

45-49

50-54

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
arjunv
 
on May 31, 2022 07:07 AM
on Jun 06, 2022 09:03 AM

Hi makumbi,

Please refer below sample example. 

HTML

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $('[id*=txtData]').on('keypress', function () {
            var number = $(this).val();
            if (number.length == 2) {
                $(this).val($(this).val() + '-');
            }
        });
    });
</script>
<asp:TextBox runat="server" ID="txtData" MaxLength="5" />

Screenshot