Skip to main content

Mask Types

  • 3 minutes to read

 

To enable masked input, select the required mask type using the TextEdit.MaskType (TextEditSettings.MaskType) property and specify a mask string via the TextEdit.Mask (TextEditSettings.Mask) property. A mask string specifies 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. 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.

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

MaskType_DateTime

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

MaskType_DateTime_2

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 or not 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.

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

MaskType_Numeric

EditMask: (# ##0.00 $) (custom)

MaskType_Numeric_2

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).

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

MaskType_Simple

Regular

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

Edit Mask: \d?\d:\d\d (short time)

MaskType_Regular

RegEx

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

or

... the value can be entered using one of several alternate forms;

or

... only characters within 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.

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

MaskType_RegEx_1

MaskType_RegEx_2

MaskType_RegEx_3