How to: Set the Input Mask

The masked text box control is an enhanced text box control that supports a declarative syntax for accepting or rejecting user input. By setting the Mask property, you can specify the allowable user input without writing any custom validation logic in your application. For more information, see the Remarks section of the MaskedTextBox class.

Setting the Mask Property Manually

If you are familiar with the characters that the Mask property supports, you can enter it manually. For a summary of the characters that the Mask property supports, see the Remarks section of the Mask property.

To set the Mask property manually

  1. In Design view, select a MaskedTextBox.

  2. In the Properties window, locate the Mask property.

  3. Type the mask that you want. For example, type ###.

Using the Input Mask Dialog Box

The Input Mask dialog box provides some predefined input masks. You can also change the predefined masks or enter your own mask manually.

To open the Input Mask dialog box

  1. In Design view, select a MaskedTextBox.

    1. Click the smart tag to open the MaskedTextBox Tasks panel.

    2. Click Set Mask.

    - or -

    1. In the Properties window, select the Mask property.

    2. Click the ellipsis button in the property value column.

    The Input Mask dialog box appears.

To use the Input Mask dialog box

  1. (Optional) Click one of the predefined masks in the list.

  2. (Optional) Edit the predefined mask in the Mask box.

  3. (Optional) Type a new mask in the Mask box. That is, you do not have to use one of the predefined masks.

    Note

    The Preview box displays the characters that the user sees in the MaskedTextBox. These characters are a guide to help the user enter the data correctly.

  4. Select or clear the Use ValidatingType check box. The Use ValidatingType check box specifies whether a data type is used to verify the data input by the user. For more information, see the ValidatingType property.

  5. Click OK.

    The mask is entered in the Mask property in the Properties window.

See also