Keep leading zeros with numeric textbox

1 Answer 956 Views
NumericTextBox
SK
Top achievements
Rank 2
Iron
Iron
SK asked on 18 Nov 2021, 08:27 PM | edited on 19 Nov 2021, 02:13 PM


                    <label for="poNumTextbox" style="color:white; line-height:3.2; padding-right:5px; padding-top:5px">PO#</label>
                    <div class="k-textbox" style="width:120px">
                        @(Html.Kendo().NumericTextBox<int>()
                            .Name("poNumTextbox")
                            .Format("#")
                            .Decimals(0)
                            .RestrictDecimals(true)
                            .Placeholder("PO #")
                        .HtmlAttributes(new { style = "font-size:inherit; width: 100%" })
                        .Spinners(false)
                        )
                    </div>

I am trying to figure out how to keep leading zeros. Numbers can be something like "00045678" with max 8 chars. However when you click out of the textbox, it is converted to "45678" I'm using numeric textbox to prevent entry of non-numeric characters. Also no decimals or special characters - numbers only. 

Thank you.

 

 

edit: nevermind, found that MaskedTextbox gives me what I need without having to misuse NumericTextbox

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 23 Nov 2021, 12:20 PM

Hi,

In general, the NumericTextBox is not designed to support such behavior. Your assumption is correct -  the MaskedTextBox would be better suited for your purposes. 

Here is an example:

<label for="poNumTextbox" style="color:white; line-height:3.2; padding-right:5px; padding-top:5px">PO#</label>
<div class="k-textbox" style="width:120px">
    @(Html.Kendo().MaskedTextBox()
    .Name("poNumTextbox")
    .Mask("00000000")
    .HtmlAttributes(new { style = "font-size:inherit; width: 100%" })
)
</div>

If you have any other questions, feel free to let me know.

 

Regards,
Mihaela
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
NumericTextBox
Asked by
SK
Top achievements
Rank 2
Iron
Iron
Answers by
Mihaela
Telerik team
Share this question
or