This section briefly explains about how to include a simple NumericTextBox in your ASP.NET Core application. You can refer ASP.NET Core Getting Started documentation page for introduction part part of the system requirements and configure the common specifications.
NumericTextBox control can be rendered by using the ejs-numerictextbox
tag helper in ASP.NET Core application. Add the below simple code to your index.cshtml
page which is available within the Views/Home
folder, to initialize the NumericTextBox.
The following example shows a basic NumericTextBox control.
<ejs-numerictextbox id="numeric" value="10" Type="text"></ejs-numerictextbox>
public ActionResult Demo()
{
return View();
}
Running the above code will display the basic NumericTextBox on the browser.
Output be like the below.
You can set the minimum and maximum range of values in the NumericTextBox using the min and max properties, so the numeric value should be in the min and max range.
The validation behavior depends on the strictMode property.
The below example demonstrates range validation.
<ejs-numerictextbox id="numeric" step="2" value="16" min="10" max="20" Type="text"></ejs-numerictextbox>
public ActionResult Range()
{
return View();
}
User can set the format of the NumericTextBox control using format property. The value will be displayed in the specified format, when the control is in focused out state. For more information about formatting the value, refer to this link.
The below example demonstrates format the value by using currency format value c2
.
<ejs-numerictextbox id="numeric" value="10" format="c2" Type="text"></ejs-numerictextbox>
public ActionResult Format()
{
return View();
}
Output be like the below.
You can restrict the number of decimals to be entered in the NumericTextBox by using the decimals and validateDecimalOnType properties. So, you can’t enter the number whose precision is greater than the mentioned decimals.
validateDecimalOnType
is false, number of decimals will not be restricted.
Else, number of decimals will be restricted while typing in the NumericTextBox.<div id='container'>
<div class='wrap'>
<ejs-numerictextbox id="strict" value="10" validateDecimalOnType="true" decimals="3" format="n3" placeholder="ValidateDecimalOnType enabled" floatLabelType="Auto"></ejs-numerictextbox>
</div>
<div class='wrap'>
<ejs-numerictextbox id="allow" value="10" decimals="3" format="n3" placeholder="ValidateDecimalOnType disabled" floatLabelType="Auto"></ejs-numerictextbox>
</div>
</div>
public ActionResult Precision()
{
return View();
}
Output be like the below.