This documentation is archived and is not being maintained.

MaskedTextProvider Class

Represents a mask-parsing service that can be used by any number of controls that support masking, such as the MaskedTextBox control.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)]
public class MaskedTextProvider : ICloneable


The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The MaskedTextBox control contains a mask, composed of literal characters and formatting elements, that it tests all user input against. Instead of permanently associating a specific mask-parsing engine with MaskedTextBox, Windows Forms provides it as a separate service, represented by the MaskedTextProvider class, which defines the syntax of the masking language discussed in the documentation for the Mask property.

Many of the members of the MaskedTextBox class refer their implementation to similarly named members of the associated MaskedTextProvider. For example, the MaskedTextBox.PromptChar property of the MaskedTextBox class refers all access to the PromptChar of the MaskedTextProvider class.

The mask-parsing engine used by MaskedTextProvider is modeled after the Masked Edit control included in Microsoft Visual Basic version 6. Its masking language is described in the documentation for the Mask property.

The following three distinct strings are involved with the MaskedTextProvider class.

String name


Input character or string

Represents the characters used as input that the mask is applied against. In actuality, the input string may be composed of multiple input operations, including Add, Replace, InsertAt, and Remove. Therefore, the input string cannot be accessed directly. However, aspects of the input string handling are available though the AllowPromptAsInput and AsciiOnly, ResetOnPrompt, and ResetOnSpace properties.


Represents the input formatting mask used to transform the input string into the formatted string. This string is set in the MaskedTextProvider and accessed primarily though the Mask property. Characteristics of the mask are also available through other members, such as the Length, PasswordChar, and PromptChar properties.

Formatted string

Represents the string that results when the full mask is applied to the input string. The formatted string can be queried with many members of the class, including Item, Length, LastAssignedPosition, MaskFull, MaskCompleted, FindEditPositionFrom, and so on. The full value of the formatted string is available from the ToDisplayString and ToString methods.


The input string may represent direct user input, as in the case of the MaskedTextBox, or may be generated by other processes not directly associated with user input/output operations.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0