MaskedTextBox.ValidatingType Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the data type used to verify the data input by the user.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

property Type^ ValidatingType {
	Type^ get ();
	void set (Type^ value);
/** @property */
public Type get_ValidatingType ()

/** @property */
public void set_ValidatingType (Type value)

public function get ValidatingType () : Type

public function set ValidatingType (value : Type)

Property Value

A Type representing the data type used in validation. The default is a null reference (Nothing in Visual Basic).

Masks do not in themselves guarantee that a user's input will represent a valid value for a given type. The following C# code shows a mask:

maskedTextBox1.Mask = "99/99/9999";

The following Visual Basic code shows a mask:

MaskedTextBox1.Mask = "99/99/9999"

This mask can demand that the user enter eight digits, but cannot verify that the user enters month, date, and year values in the correct range; "12/20/2003" and "70/90/0000" are equally valid as far as the mask is concerned.

You can use ValidatingType to verify whether the data entered by the user falls within the correct range—in the previously mentioned case, by assigning it an instance of the DateTime type. The current text in the control will be validated either when the user leaves the control. You can determine whether or not the data fails validation by monitoring for the TypeValidationCompleted event. MaskedTextBox will only perform the check against ValidatingType if MaskCompleted is true.

If you want to use your own custom data types with ValidatingType, you must implement a static Parse method that takes a string as a parameter. This method must be implemented with one or both of the following signatures:

public static Object Parse(string)

public static Object Parse(string, IFormatProvider)

For an example of how to implement parsing on a custom data type, see MaskedTextBox Control Sample.

The following code example attempts to parse the user's input as a valid DateTime. If it fails, the TypeValidationCompleted event handler displays an error message to the user. If the value is a valid DateTime, the code performs an additional check to ensure that the date supplied is not prior to today's date. This code example requires that your Windows Forms project contains a MaskedTextBox control named MaskedTextBox1 and a ToolTip control named ToolTip1.

No code example is currently available or this language may not be supported.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions