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

Mask Type: Simplified Regular Expressions

  • 3 minutes to read

Simplified regular expressions allow you to specify the entered text’s pattern.

Note

Run the XtraEditors demo to try out input masks.

Tip

Simplified regular expressions support backward compatibility with XtraEditors version 2. We recommend that you use RegEx type syntax because it supports additional features like alternative validation and autocomplete. See Extended Regular Expressions for more information.

Mask Type and Mask Expression

The TextEdit.Properties.Mask property provides access to a MaskProperties class instance that specifies an input mask. Set the MaskProperties.MaskType property to Regular to enable the simplified regex mask format. Use the MaskProperties.EditMask property to specify the mask expression.

Metacharacters

Metacharacters specify characters users can enter at the corresponding positions. The table below lists the available metacharacters.

Character Description
. Any single character.
[aeiou] Any single character from the specified character set.
[^aeiou] Any single character not from the specified character set.
[0-9a-fA-F] Any single character from the specified character range.
\w Any single alphanumeric character. The same as [a-zA-Z_0-9].
\W Any single non-alphanumeric character. The same as [^a-zA-Z_0-9].
\d Any single numeric character. The same as [0-9].
\D Any single non-numeric character. The same as [^0-9].

Quantifiers

Quantifiers follow a metacharacter and specify how many times the character should be repeated. The table below lists the available qualifiers.

Quantifier Description Examples
* Zero or more matches. The same as {0,}. [a-zA-Z]*, \w*
+ One or more matches. The same as {1,}. [a-zA-Z]+, \w+
? Zero or one matches. The same as {0,1}. [a-zA-Z]?, \w?
{n} Exactly n matches. [0-9]{2}
{n,} At least n matches. [0-9]{2,}
{n,m} At least n, but not more than m matches. [0-9]{2,7}

Special Characters

Special characters convert the entered text to uppercase/lowercase, insert delimiters and currency symbols. The table below lists the available special characters.

Character Description
> Converts subsequent characters to uppercase.
< Converts subsequent characters to lowercase.
<> Discards case conversion for subsequent characters.
/ Separates months, days, and years. The culture’s DateSeparator property specifies the actual character.
: Separates hours, minutes, and seconds. The culture’s TimeSeparator property specifies the actual character.
$ Inserts the currency symbol. The culture’s CurrencySymbol property specifies the actual character.

Literal Characters

Literal characters are arbitrary read-only characters in the edit box. If you add a character that is not a meta or special character into a mask expression, the character is displayed in the edit box as is. To display a meta or special character as a literal, precede it with a backslash.

Examples

Example 1

[0-9A-F]* - a mask to enter hexadecimal values of any length.

CD_Mask_Regular_hex

Example 2

[0-9A-F]{2,} - a mask to enter a hexadecimal value that consists of at least two digits.

If the user enters less than two digits, the editor displays a notification.

CD_Mask_Regular_hex_invalid

Example 3

\d*\.\d{2} - a mask to enter a number that has two decimal digits.

CD_Mask_Regular_number2

See Also