Skip to main content
A newer version of this page is available. .

Mask Types

  • 4 minutes to read

To enable masked input, select the required mask type via the TextEdit.MaskType (TextEditSettings.MaskType) property and specify a mask string via the TextEdit.Mask (TextEditSettings.Mask) property. A mask string identifies a data input pattern. You can use either predefined mask strings or compose your own mask expressions. Mask strings should be set according to the mask type. The available mask types are listed in the following table:

Mask Type

Use this mask if…

Description

Samples

None

 

Masked mode is disabled.

 

DateTime

DateTimeAdvancingCaret

…an editor should accept date/time values in a specific format.

Masks of the DateTime/DateTimeAdvancingCaret type significantly simplify inputting date/time values.

Predefined masks can be used to enter values using common date/time patterns. It’s also possible to create custom masks that specify which parts (year, month, day, hour, minute, etc) of a date/time value can be edited. The syntax used for these masks is similar to the date/time formats described in the Date and Time Format Strings topic in MSDN.

The data input pattern imposed by the mask is affected by the current culture’s settings. These settings can be customized via the Regional Options dialog in the control panel.

See the Mask Type: Date-time topic for more information.

EditMask: D (long date pattern); Current culture: English (USA)

CD_MaskOverview_DateTime_D

EditMask: yyyy-MMM-d, HH:mm:ss (custom date pattern); Current culture: French (France)

CD_MaskOverview_DateTime_Custom

Numeric

…an editor should accept numeric values in a specific format.

Masks of the Numeric type significantly simplify the input of numeric values (currency, integer, float, etc).

Masks in this mode allow numeric values to be entered using various common and custom patterns. It’s possible to specify the number of optional and required digits to the left and to the right of the decimal separator, whether to display thousand separators, etc. The syntax used for these masks is similar to the numeric formats described in the Numeric Format Strings topic in MSDN.

Specific masks are dependent upon the current culture’s settings.

If your numeric mask allows entering a decimal part, you can hide the decimal separator for integer values by setting the attached NumericMaskOptions.AlwaysShowDecimalSeparator property to false:

<dxe:TextEdit dxe:NumericMaskOptions.AlwaysShowDecimalSeparator="False" Mask="##.##" MaskType="Numeric" .../>

See the Mask Type: Numeric topic for more information.

EditMask: c (currency); Current culture: English (USA)

CD_MaskOverview_Numeric_c

EditMask: # ##0.00 $;(# ##0.00 $) (custom); Current culture: French (France)

CD_MaskOverview_Numeric_custom

Simple

…the string an end-user can enter is of a fixed format (without alternatives) and a fixed length (for instance, phone numbers and alpha-numeric sequences).

This mask type also supports optional characters (for instance, it’s possible to specify that the code of a phone number should contain 0 to 3 digits). Any auxiliary characters can be included in these masks and these auxiliary characters will be displayed in the edit box as is and will be skipped while editing (for instance, hyphens in phone numbers).

See the Mask Type: Simple topic for more information.

EditMask: (999)000-00-00 (phone number)

CD_MaskOverview_Simple_phone

Regular

In this mode masks use the simplified regular expression syntax, which is similar to the one that was implemented in version 2 of the XtraEditors. This mode is designed for backwards compatibility. Instead, use the RegEx mode which implements full functional regular expressions which give you more flexibility to control data input.

For information on the regular expression syntax used in this mode see the Mask Type: Simplified Regular Expressions topic.

RegEx

… the length of the string an end-user can enter is not fixed;

or

… the value can be entered using one of several alternative forms;

or

… characters only from a specific range can be entered at a specific position;

or

… the auto-complete feature should be available (an end-user enters text and the editor completes this variant if there are no other alternatives)

In this mode you can construct masks using full functional regular expressions. This gives you great flexibility to control data input. For instance, it’s possible to create a single mask that will allow end-users to enter a time value using either the 12-hour or 24-hour format.

See the Mask Type: Extended Regular Expressions topic for information on the regular expressions syntax used in this mode. The syntax used by masks in this mode is similar to the syntax defined by the POSIX ERE specification.

EditMask: ((+\d)?(\d{3}))?\d{3}-\d\d-\d\d (several valid forms to enter a phone number)

CD_MaskOverview_RegEx_phone1

CD_MaskOverview_RegEx_phone2

CD_MaskOverview_RegEx_phone3

See Also