Search results

Getting Started

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.

Adding component to the Application

NumericTextBox component 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 component.

tagHelper
demo.cs
@section ControlsSection{

 <ejs-numerictextbox id="numeric" value="10" Type="text"></ejs-numerictextbox>

}
public ActionResult Demo()
{
    return View();
}

Output be like the below.

NumericTextBox Sample

Run the application

After successful compilation of your application, simply press F5 to run the application.

The below example shows the NumericTextBox.

tagHelper
demo.cs
@section ControlsSection{

 <ejs-numerictextbox id="numeric" value="10" Type="text"></ejs-numerictextbox>

}
public ActionResult Demo()
{
    return View();
}

Range validation

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.

tagHelper
range.cs
@section ControlsSection{

      <ejs-numerictextbox id="numeric" step="2" value="16" min="10" max="20" Type="text"></ejs-numerictextbox>
}
public ActionResult Range()
{
    return View();
}

Formatting the value

User can set the format of the NumericTextBox component using format property. The value will be displayed in the specified format, when the component 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.

tagHelper
format.cs
@section ControlsSection{

<ejs-numerictextbox  value="10" format="c2" Type="text"></ejs-numerictextbox>

}
public ActionResult Format()
{
    return View();
}

Output be like the below.

NumericTextBox Sample

Precision of numbers

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.

  • If validateDecimalOnType is false, number of decimals will not be restricted. Else, number of decimals will be restricted while typing in the NumericTextBox.
tagHelper
precision.cs
@section ControlsSection{
    <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.

NumericTextBox Sample

See Also