# MaskedTextInput

`RadMaskedTextInput` represents a control that can be used to restrict the input of text values.

To use the RadMaskedTextInput control in your projects, add references to the following assemblies:

* **Telerik.Licensing.Runtime**
* **Telerik.Windows.Controls**
* **Telerik.Windows.Controls.Input**
* **Telerik.Windows.Data**

You can find more info [here](http://www.telerik.com/help/wpf/installation-installing-controls-dependencies-wpf.html).

> tip With the 2025 Q1 release, the Telerik UI for WPF has a new licensing mechanism. You can learn more about it [here](https://www.telerik.com/products/wpf/documentation/installation/licensing/installing-license-key).

## Declaratively defined MaskedTextInput

The following example shows how to define the control and set few of its properties.

**Define RadMaskedTextInput in XAML**

```XAML
<telerik:RadMaskedTextInput EmptyContent="Enter digits"
	                            InputBehavior="Replace"
	                            Mask="a20"
	                            SelectionOnFocus="SelectAll"
	                            TextMode="PlainText"
	                            UpdateValueEvent="LostFocus"
	                            Value="Sample Text" />
```

> caption RadMaskedTextInput example

![WPF RadMaskedInput RadMaskedTextInput example](https://www.telerik.com/products/wpf/documentation/assets/d07fc4a3531bd6ebe84b4fe06a5a6b1e/radmaskedinput_textinput_default.png)

## Data Binding

RadMaskedTextInput's `Value` property is of type **string** and you have to bind it to ViewModel's property of type **string**.

> important Binding to **object** is not support and may result in unpredictable behavior.

**Define the view model**

```XAML
public class ViewModel : ViewModelBase
    {
private string text;

public ViewModel()
{
    this.Text = "Sample Text";
}

public string Text
{
    get { return this.text; }
    set
    {
        if (this.text != value)
        {
            this.text = value;
            this.OnPropertyChanged("Text");
        }
    }
}
    }
```

**Binding the Value property**

```XAML
<telerik:RadMaskedTextInput EmptyContent="Enter digits"
	                            InputBehavior="Replace"
	                            Mask="a20"
	                            SelectionOnFocus="SelectAll"
	                            TextMode="PlainText"
	                            UpdateValueEvent="LostFocus"
	                            Value="{Binding Text}" />
```

## Setting the Value Mode

The value mode allows you to set the behavior of the Value property in a mask scenario (when the Mask property is set). By default the Value property holds the characters without including the placeholders and the literals defined in the mask. You can alter this and allow the value to hold also literal and placeholders by setting the `ValueMode` property of the control.

Read more about this in the [Value Mode](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/value-mode) article.

## FormatString

You can format the entered value using the `FormatString` property of the RadMaskedTextInput control. The property works with the standard .NET string formats. The format will be applied only when the control is unfocused.

**Setting the FormatString property**

```XAML
<telerik:RadMaskedTextInput Value="Adam"
								Mask="a4" 
	                            FormatString="{}UserName: {0} NickName: {0}"/>
```

> caption Showing the text value when the control is focused

![WPF RadMaskedInput Showing the text value when the control is focused](https://www.telerik.com/products/wpf/documentation/assets/332dff53f7844914efaf70d4e8bc7ffe/radmaskedinput_textinput_format_string_focused.png)

> caption Showing the text value when the control is unfocused

![WPF RadMaskedInput Showing the text value when the control is unfocused](https://www.telerik.com/products/wpf/documentation/assets/93148dd4965b486f488a5c1539be7dac/radmaskedinput_textinput_format_string.png)

## Accepts Return

The `RadMaskedTextInput` control allows you to span the input text on multiple lines. This is controlled via the `AcceptsReturn` property and its default value is **True**. To disable the text to be inputted on multiple lines, set the AcceptsReturn property to **False**.

**Disable multi-line text input**

```XAML
<telerik:RadMaskedTextInput AcceptsReturn="False"/>
```

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/getting-started)
* [MaskedNumericInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/numeric)
* [MaskedCurrencyInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/currency)
* [MaskedDateTimeInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/datetime)
* [Common Features](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/common)
