# Getting Started with WPF MaskedInput

The **RadMaskedInput** controls use a mask to distinguish between proper and improper user input. The **RadMaskedInput** controls are enhanced TextBox controls that support a declarative syntax for accepting or rejecting user input. Using the **Mask** property, you can specify the following input without writing any custom validation logic in your application:

* Required input characters.

* Optional input characters.

* The type of input expected at a given position in the mask; for example, a digit, or an alphabetic or alphanumeric character.

* Mask literals, or characters that should appear directly in the **RadMaskedInput** control; for example, the hyphens (-) in a phone number, or the currency symbol in a price.

When a **RadMaskedInput** control is displayed at run time, it represents the mask as a series of prompt characters and optional literal characters. Each editable mask position, representing a required or optional input, is shown with a single placeholder character. For example, the number sign (#) is used as a placeholder for a numeric character input. You can use the [Placeholder](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/placeholder) property to specify a custom placeholder character. The [EmptyContent](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/watermark) property could be used to determine what will be displayed when the user specifies a null value and the control loses its focus.

As the user types input into a **RadMaskedInput** control, valid input characters replace their respective placeholder characters in a sequential fashion. If the user types an invalid input character, no replacement occurs. You can provide your own custom error by handling the **ValueChanging** or/and **ValueChanged** events.

You can use the **Value** property, to get the user input without the formatted characters. The **Text** property will always retreive the user's input formatted according to the **Mask** and the **TextMode** property.

Masks do not necessarily guarantee that a user's input will represent a valid value for a given type; for example, -9 could be entered for an age in years. You can verify that a user's input represents a valid value by taking advantage of the **RadMaskedInput** controls' built in support for WPF [Validation](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/validation/validation).

## RadMaskedInput Controls

There are four **RadMaskedInput** controls that you can use in order to further specify how masks should be interpreted:

* [RadMaskedNumericInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/numeric) - the control is used to display numeric values. This is why its **Value** property is of type **double?**.

* [RadMaskedCurrencyInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/currency) - the control is used to display culture-aware currency values. This is why its **Value** property is of type **decimal?**.

* [RadMaskedTextInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/text) - the control is used to display text characters. This is why its **Value** property is of type **string**.

* [RadMaskedDateTimeInput](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/maskedinput-controls/datetime) - the control is used to display **DateTime** values. This is why its **Value** property is of type **System.DateTime?**.

## Adding Telerik Assemblies Using NuGet

To use **RadMaskedInput** when working with NuGet packages, install the `Telerik.Windows.Controls.Input.for.Wpf.Xaml` package. The [package name may vary](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/nuget/available-packages) slightly based on the Telerik dlls set - [Xaml or NoXaml](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/xaml-vs-noxaml)

Read more about NuGet installation in the [Installing UI for WPF from NuGet Package](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/nuget/nuget-installation) article.

> 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).

## Adding Assembly References Manually

If you are not using NuGet packages, you can add a reference to the following assemblies:

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

You can find more info [here](https://www.telerik.com/products/wpf/documentation/common-information/installation-installing-dependencies-wpf).

After adding the NuGet package or manually referencing the assemblies, you can declare a new **RadMaskedInput** control as any normal WPF control.

**Example 1: Declare RadMaskedInput controls in XAML**

```XAML
<UserControl 
	            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <StackPanel x:Name="LayoutRoot"
	         Background="White">
        <telerik:RadMaskedTextInput x:Name="radMaskedTextInput" />
        <telerik:RadMaskedCurrencyInput x:Name="radMaskedCurrencyInput" />
        <telerik:RadMaskedDateTimeInput x:Name="radMaskedDateTimeInput" />
        <telerik:RadMaskedNumericInput x:Name="radMaskedNumericInput" />
    </StackPanel>
</UserControl>
```

## Set the Mask Property

Although each **RadMaskedInput** component is designed to work with specific type of input, you can further restrict the entered value through the **Mask** property.

* **Mask** - gets or sets a string of characters that constrain user input. The **Mask** property may contain literals and special mask characters. You can use the back slash character to escape any special mask characters so that they are displayed as literals.

The following code example initializes the **RadMaskedDateTimeInput** to accept a date in a long date format.

**Example 2: Set mask property**

```XAML
<telerik:RadMaskedDateTimeInput  Mask="D"/>
```

## Change the Default Placeholder Character

The **Placeholder** property represents the character displayed in any blank space defined by a **Mask** character. By default the character is an underscore.

**Example 3: Set custom character to the Placeholder property**

```XAML
<telerik:RadMaskedCurrencyInput Placeholder="$" />
```

## Change the Culture

The **Culture** property allows you to set the current language and culture from a drop-down list at design-time or to assign a new **CultureInfo** instance at run-time.

The following code example initializes the **RadMaskedDateTimeInput** to accept a Bulgarian date in a long date format.

**Example 3: Change the Culture property**

```XAML
<telerik:RadMaskedDateTimeInput Mask="D"
	                                Culture="bg-BG" />
```

![WPF RadMaskedInput Bulgarian Culture](https://www.telerik.com/products/wpf/documentation/assets/d035f5b96a6f49a041c1e7fadf4db591/radmaskedinput_getting_started_culture_datetime.png)

> tip For more information check out the following [Globalization Support](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/globalization) topic.

## Set Watermark

You can set a watermark content to the **RadMaskedInput** controls by using the **EmptyContent** and the **EmptyContentTemplate** properties. When the **Value** of a **RadMaskedTextInput** control is null or empty the **EmptyContent** will be displayed.

**Example 4: Set custom value to the EmptyContent property**

```XAML
<telerik:RadMaskedTextInput Mask="####" EmptyContent="Please Enter Four Digits" />
```

## Setting a Theme

The controls from our suite support different themes. You can see how to apply a theme different than the default one in the [Setting a Theme](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-setting-a-theme-overview) help article.

> important Changing the theme using implicit styles will affect all controls that have styles defined in the merged resource dictionaries. This is applicable only for the controls in the scope in which the resources are merged.

To change the theme, you can follow the steps below:

* Choose between the themes and add reference to the corresponding theme assembly (ex: **Telerik.Windows.Themes.Windows8.dll**). You can see the different themes applied in the **Theming** examples from our [WPF Controls Examples](https://demos.telerik.com/wpf/) application.

* Merge the ResourceDictionaries with the namespace required for the controls that you are using from the theme assembly. For **RadMaskedInput**, you will need to merge the following resources:

  * **Telerik.Windows.Controls**
  * **Telerik.Windows.Controls.Input**

**Example 4** demonstrates how to merge the ResourceDictionaries so that they are applied globally for the entire application.

**Example 4: Merge the ResourceDictionaries**

```XAML
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml"/>
            <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml"/>
            <ResourceDictionary Source="/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
```

**Figure 1** shows **RadMaskedInput** with the **Windows8** theme applied.

> caption RadMaskedInput with the Windows8 theme

![Telerik WPF MaskedInput-Windows8](https://www.telerik.com/products/wpf/documentation/assets/21bdc36328ecde57baf3e6978730a386/radmaskedinput-windows8.png)

## Telerik UI for WPF Learning Resources

* [Telerik UI for WPF MaskedInput Component](https://www.telerik.com/products/wpf/maskedinput.aspx)
* [Getting Started with Telerik UI for WPF Components](https://www.telerik.com/products/wpf/documentation/getting-started/first-steps-nuget)
* [Telerik UI for WPF Installation](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/installation-guide)
* [Telerik UI for WPF and WinForms Integration](https://www.telerik.com/products/wpf/documentation/common-information/winforms-integration/overview)
* [Telerik UI for WPF Visual Studio Templates](https://www.telerik.com/products/wpf/documentation/installation/manual-setup-guides/visual-studio-templates)
* [Setting a Theme with Telerik UI for WPF](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-setting-a-theme-overview)
* [Telerik UI for WPF Virtual Classroom (Training Courses for Registered Users)](https://learn.telerik.com/learn/course/external/view/elearning/16/telerik-ui-for-wpf)
* [Telerik UI for WPF License Agreement](https://www.telerik.com/purchase/license-agreement/wpf-dlw-s)

## See Also

* [RadMaskedInput Controls Overview](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/overview)
* [Events Overview](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/events/overview)
* [Common Features](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/common)
* [MaskTokens](https://www.telerik.com/products/wpf/documentation/controls/radmaskedinput/features/mask-tokens)
* [Editing Control Templates](https://www.telerik.com/products/wpf/documentation/styling-and-appearance/styling-apperance-editing-control-templates)
