ASP.NET Core MaskedTextBox Overview
The MaskedTextBox is part of Telerik UI for ASP.NET Core, a
professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
The Telerik UI MaskedTextBox TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI MaskedTextBox widget.
The MaskedTextBox enables a controlled text input that is based on a specific format. The helper enables you to define its value and mask value, and set custom mask rules, prompt characters, and culture names. Each mask can contain mask rules and mask literals. The mask literals are automatically entered for the user and cannot be removed. You can also use the MaskedTextBox predefined rules which specify the required or optional digit, letter, or character input.
Basic Configuration
The following example demonstrates the basic configuration for the MaskedTextBox.
@(Html.Kendo().MaskedTextBox()
.Name("maskedtextbox") // The name of the MaskedTextBox is mandatory. It specifies the "id" attribute of the MaskedTextBox.
.Mask("(000) 000-0000") // Set the mask value of the MaskedTextBox.
.Value("(123) 345-6789") // Set the value of the MaskedTextBox.
)
<kendo-maskedtextbox name="phone_number" mask="(999) 000-0000" value="555 123 4567"></kendo-maskedtextbox>
Functionality and Features
Events
You can subscribe to all MaskedTextBox events. For a complete example on basic MaskedTextBox events, refer to the demo on using the events of the MaskedTextBox.
The following example demonstrates how to subscribe to events by a handler name.
@(Html.Kendo().MaskedTextBox()
.Name("maskedtextbox")
.Events(e => e
.Change("maskedtextbox_change")
)
)
<script>
function maskedtextbox_change() {
// Handle the change event.
}
</script>
<kendo-maskedtextbox name="maskedtextbox" on-change="maskedtextbox_change"></kendo-maskedtextbox>
<script>
function maskedtextbox_change() {
// Handle the change event.
}
</script>
Handling by Template Delegate
The following example demonstrates how to subscribe to events by a template delegate.
@(Html.Kendo().MaskedTextBox()
.Name("maskedtextbox")
.Events(e => e
.Change(@<text>
function() {
// Handle the change event inline.
}
</text>)
)
)
<kendo-maskedtextbox name="maskedtextbox"
on-change="
function() {
// Handle the change event inline.
}">
</kendo-maskedtextbox>
Referencing Existing Instances
To reference an existing Telerik UI MaskedTextBox instance, use the jQuery.data()
method. Once a reference is established, use the MaskedTextBox client-side API to control its behavior.
The following example demonstrates how to access an existing MaskedTextBox instance.
// Place the following after your Telerik UI MaskedTextBox for ASP.NET Core declaration.
<script>
$(function() {
// The Name() of the MaskedTextBox is used to get its client-side instance.
var maskedtextbox = $("#maskedtextbox").data("kendoMaskedTextBox");
});
</script>