Mask Type: Simplified Regular Expressions

  • 5 minutes to read
NOTE

In this mode masks use the simplified regular expression syntax, and 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.

Simplified regular expressions don't support as many features as Extended Regular Expressions. For example, they do not support alternative valid forms for values, they also lack the autocomplete feature, etc.

Simplified Regular Expressions

Simplified regular expressions can be used in two cases:

  • when you specify a custom range of characters for a specific position,
  • when you specify a mask of variable length.

To construct masks using the simplified regular expressions set the editor's TextEdit.MaskType (or the TextEditSettings.MaskType for the in-place editors) property to MaskType.Regular. The mask itself should be specified using the TextEdit.Mask (or TextEditSettings.Mask) property.

A mask represents a string which can consist of metacharacters, quantifiers, special, and literal characters.

Metacharacters

Metacharacters are used to represent a range of symbols. An end user can enter text only in the positions corresponding to metacharacters. When a metacharacter is found in a specific position in the mask an end user can enter any character from the related range in this position in the edit box. The following table lists the available metacharacters:

Character Description
. Matches any character.
[aeiou] Matches any single character included in the specified set of characters.
[^aeiou] Matches any single character, which is not included in the specified set of characters.
[0-9a-fA-F] Use of a hyphen (-) allows specification of contiguous character ranges.
\w Matches any word character. \w is the same as [a-zA-Z_0-9].
\W Matches any nonword character. \W is the same as [^a-zA-Z_0-9].
\d Matches any decimal digit. Same as [0-9].
\D Matches any nondigit. Same as [^0-9].

Quantifiers

These are special characters which denote the number of repetitions for the preceding character. Review the table below for the list of qualifiers and their descriptions.

Quantifier Description
* Specifies zero or more matches; for example, \w* or [a-zA-Z]*. Same as {0,}.
+ Specifies one or more matches; for example, \w+ or [a-zA-Z]+. Same as {1,}.
? Specifies zero or one matches; for example, \w? or [a-zA-Z]?. Same as {0,1}.
{n} Specifies exactly n matches; for example, [0-9]{2}.
{n,} Specifies at least n matches; for example, [0-9]{2,}.
{n,m} Specifies at least n, but no more than m, matches.

Special Characters

The following table lists the available special characters which are used to control the case of the input string and to represent various delimiters and currency symbols.

Character Description
> If a > character appears in the mask, all the characters that follow it are in uppercase until the end of the mask or until a , character is encountered.
< If a < character appears in the mask, all the characters that follow it are in lowercase until the end of the mask or until a > character is encountered.
<> If these two characters appear together in the mask, no case checking is done and the data is formatted with the case used by the end-user during data entry.
/ A / character is used to separate months, days, and years in dates. If the character that separates months, days, and years is different in the regional settings of the system that the application runs on that character is used instead.
: A : character is used to separate hours, minutes, and seconds in time values. If the character that separates hours, minutes, and seconds is different in the regional settings of the system that the application runs on that character is used instead.
$ A $ character is used to designate currency values. If the character that designates currency values is different in the regional settings of the system that the application runs on that character is used instead.

Literal Characters

A character which is not used to represent a metacharacter nor quantifier nor special character is called a literal. Literals are inserted automatically as is into the edit box in the positions defined by the mask. An end-user has no need to enter literal characters. The cursor skips over them during editing.

A symbol used to represent a reserved character can also appear as a literal if preceded by a backslash (\).

Examples

  1. A mask for entering hexadecimal values of any length: [0-9A-F]*

    The [0-9A-F] substring specifies that any character from the [0-9] and [A-F] ranges can be entered. The * quantifier denotes that characters from the specified range can appear an unlimited number of times.

    CD_Mask_Regular_hex

  2. A mask that requires an end user enter at least two digits of a hexadecimal number: [0-9A-F]{2,}

    If a user enters less than two digits, the editor indicates that the value is not valid:

    CD_Mask_Regular_hex_invalid

  3. A mask for entering a number that has two digits in its fractional part: \d*\.\d{2}

    Since the . character is reserved the \. substring is used to insert the dot as a literal into the mask.

    CD_Mask_Regular_number2