This is a migrated thread and some comments may be shown as answers.

Min Max Values

2 Answers 1510 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 23 May 2020, 04:06 PM

Hello:

 

Is there no way to limit the value of a NumericTextBox with a Type of Int32 (or anything other than a decimal value)?

2 Answers, 1 is accepted

Sort by
0
Doug
Top achievements
Rank 1
answered on 23 May 2020, 04:10 PM
please disregard this post
0
Svetoslav Dimitrov
Telerik team
answered on 25 May 2020, 10:48 AM

Hello Doug,

I am happy to see you managed to resolve that question on your own.

For future questions of that sort I am posting two possible solutions (that you can, of course, combine):

Using the Min and Max parameters of the component:

 

<TelerikNumericTextBox @bind-Value="@TheValue" Min="-100" Max="10000"></TelerikNumericTextBox>

@code {
    public int TheValue { get; set; }
}

 

Using Form Validation:

 

@using System.ComponentModel.DataAnnotations

<EditForm Model="@MyModel">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <TelerikNumericTextBox @bind-Value="@MyModel.TheValue"></TelerikNumericTextBox>

</EditForm>


@code {
    MyDataModel MyModel = new MyDataModel();

    public class MyDataModel
    {
        [Range(-100, 1000, ErrorMessage = "The number should be between {1} and {2}")]
        public int TheValue { get; set; }
    }
}

 

Regards,
Svetoslav Dimitrov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
NumericTextBox
Asked by
Doug
Top achievements
Rank 1
Answers by
Doug
Top achievements
Rank 1
Svetoslav Dimitrov
Telerik team
Share this question
or