System.Windows.Forms.MaskedTextBox.Mask Property

Gets or sets the input mask to use at run time.

Syntax

[System.ComponentModel.DefaultValue("")]
[System.ComponentModel.MergableProperty(false)]
[System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)]
[System.ComponentModel.Editor("System.Windows.Forms.Design.MaskPropertyEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[System.ComponentModel.Localizable(true)]
public string Mask { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

MaskedTextBox.Mask is the default property for the System.Windows.Forms.MaskedTextBox class.

MaskedTextBox.Mask must be a string composed of one or more of the masking elements, as shown in the following table. The masking language used by System.Windows.Forms.MaskedTextBox is defined by its associated MaskedTextBox.MaskedTextProvider. The standard provider specifies a masking language based upon the one used by the Masked Edit control in vbprvb 6.0, and should be very familiar to users migrating from that platform.

0

Digit, required. This element will accept any single digit between 0 and 9.

9

Digit or space, optional.

#

Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the MaskedTextBox.Text property. Plus (+) and minus (-) signs are allowed.

L

Letter, required. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z] in regular expressions.

?

Letter, optional. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z]? in regular expressions.

&

Character, required. If the MaskedTextBox.AsciiOnly property is set to true, this element behaves like the "L" element.

C

Character, optional. Any non-control character. If the MaskedTextBox.AsciiOnly property is set to true, this element behaves like the "?" element.

A

Alphanumeric, required. If the MaskedTextBox.AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z. This mask element behaves like the "a" element.

a

Alphanumeric, optional. If the MaskedTextBox.AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z. This mask element behaves like the "A" element.

.

Decimal placeholder. The actual display character used will be the decimal symbol appropriate to the format provider, as determined by the control's MaskedTextBox.FormatProvider property.

,

Thousands placeholder. The actual display character used will be the thousands placeholder appropriate to the format provider, as determined by the control's MaskedTextBox.FormatProvider property.

:

Time separator. The actual display character used will be the time symbol appropriate to the format provider, as determined by the control's MaskedTextBox.FormatProvider property.

/

Date separator. The actual display character used will be the date symbol appropriate to the format provider, as determined by the control's MaskedTextBox.FormatProvider property.

$

Currency symbol. The actual character displayed will be the currency symbol appropriate to the format provider, as determined by the control's MaskedTextBox.FormatProvider property.

<

Shift down. Converts all characters that follow to lowercase.

>

Shift up. Converts all characters that follow to uppercase.

|

Disable a previous shift up or shift down.

\

Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.

All other characters

Literals. All non-mask elements will appear as themselves within System.Windows.Forms.MaskedTextBox. Literals always occupy a static position in the mask at run time, and cannot be moved or deleted by the user.

If you change a mask when System.Windows.Forms.MaskedTextBox already contains user input filtered by a previous mask, System.Windows.Forms.MaskedTextBox will attempt to migrate that input into the new mask definition. If it fails, it will clear the existing input. Assigning a zero-length string as the mask will preserve any existing data in the control. When used with a zero-length mask, System.Windows.Forms.MaskedTextBox behaves like a single-line System.Windows.Forms.TextBox control.

The decimal (.), thousandths (,), time (:), date (/), and currency ($) symbols default to displaying those symbols as defined by the application's culture. You can force them to display symbols for another culture by using the MaskedTextBox.FormatProvider property.

Character insertion into the mask at run time is controlled by the MaskedTextBox.InsertKeyMode property. Users can navigate through the mask by using the left and right arrow keys or the mouse cursor, and can skip optional positions in the mask by entering a space.

Note:

System.Windows.Forms.MaskedTextBox supports all Unicode characters except for surrogates and vertically combined characters.

The following table shows example masks.

00/00/0000

A date (day, numeric month, year) in international date format. The "/" character is a logical date separator, and will appear to the user as the date separator appropriate to the application's current culture.

00->L<LL-0000

A date (day, month abbreviation, and year) in United States format in which the three-letter month abbreviation is displayed with an initial uppercase letter followed by two lowercase letters.

(999)-000-0000

United States phone number, area code optional. If users do not want to enter the optional characters, they can either enter spaces or place the mouse pointer directly at the position in the mask represented by the first 0.

$999,999.00

A currency value in the range of 0 to 999999. The currency, thousandth, and decimal characters will be replaced at run time with their culture-specific equivalents.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0