Skip to main content

Mask Types

  • 3 minutes to read

To enable masked input, set the TextEdit.TextInputSettings property to DevExpress.UI.Xaml.Editors.TextInputMaskSettings. 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 requires that date/time values be in a specific format.

Masks of the DateTime/DateTimeAdvancingCaret type significantly simplify the input of 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 Standard Date and Time Format Strings topic in MSDN.

EditMask: D (long date pattern);

Mask(D)

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

Mask(yyyy-MMM-d HHmmss)

Numeric

…an editor requires that numeric values be 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 is 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 Standard Numeric Format Strings topic in MSDN.

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

EditMask: c (currency);

Mask(c)

EditMask: # ##0.00 $ (custom);

Mask(# ##0.00 $)

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, when it is 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. These auxiliary characters will be displayed in the edit box as is, and will be skipped while editing (for instance, hyphens in phone numbers).

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

Mask((999)000-00-00)

Regular

In this mode, masks use the simplified regular expression syntax. This mode is designed for backwards compatibility. Instead, use the RegEx mode, which implements full functional regular expressions that give you more flexibility to control data input.

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

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

or

… the auto-complete feature is 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.

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

Mask(regex)