How to Set a Max Length for .NET Core AutoComplete Control?
This article explains how to limit the number of characters a user can enter in the ASP.NET Core AutoComplete control by setting a maximum length. This is achieved using the htmlAttributes property, which allows adding custom HTML attributes to the input element.
@{
var data = new string[] { "Badminton", "Basketball", "Cricket", "Football", "Golf", "Gymnastics", "Hockey", "Tennis" };
IDictionary<string, object> customAttribute = new Dictionary<string, object>()
{
{ "maxlength", "5" },
};
}
<div style="margin:150px auto; width: 50%">
<ejs-autocomplete id="games" htmlAttributes="customAttribute" dataSource="@data" placeholder="e.g. Basketball" popupHeight="220px"></ejs-autocomplete>
</div>
In this example, the htmlAttributes property is used to set the maxlength attribute to 5, limiting the input field to 5 characters. With this setting, users can only enter up to 5 characters in the input field.
By using the htmlAttributes property, you can customize the behavior of the input field and improve the functionality of the AutoComplete component. For more information, refer to the AutoComplete documentation.
Conclusion
I hope you enjoyed learning on how to set a max length for .NET Core AutoComplete control.
You can refer to our ASP.NET Core AutoComplete feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core AutoComplete example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!