If you define an input mask using the Mask property, each character position in the Masked Edit control maps to either a placeholder of a specified type or a literal character.
If you attempt to enter a character that conflicts with the input mask, the control generates a Validationerror event. The input mask prevents you from entering invalid characters into the control.
The Masked Edit control also validates the values of the Text property at run time. If you set the Text property so that it conflicts with the input mask, the control generates a run-time error.
The MaskedEdit control is used to prompt users for data input using a mask pattern. You can also use it to prompt for dates, currency, and time, or to convert input data to all upper- or lowercase letters. For example, to prompt the user to enter a phone number, you can create the following input mask: "(___) - ___ - ____". If you don't use an input mask, the MaskedEdit control behaves much like a standard text box.
To create an input mask, you combine mask characters with literal characters. Literal characters are characters which rather than representing some data type or format, are used as themselves. For example, to create an input mask for a phone number you define the Mask property as follows:
MaskEdBox1.Mask = (###) - ### - ####
At run time, the MaskedEdit control would look like the following:
"(___) - ___ - ____"
If you want to use a mask character as a literal, you can precede the mask character with a backslash (\). For example, if you want the pound sign (#) to display, you set the mask as follows:
MaskEdBox1.Mask = "\##"
You use the Format property with the Mask property. For example, to create a mask that prompts for a Short Date input that displays in the Long Date format, you set the Mask and Format properties as follows:
MaskEdBox1.Mask = "##-##-##"
MaskEdBox1.Format = "dddddd"
When the user enters the date in the short format (11-12-09, for instance), the MaskedEdit control verifies that the entered data is valid, and then, when the focus passes to the next control, it is displayed as "Thursday, November 12, 2009".