Mask types in WinUI Masked TextBox

19 Dec 20233 minutes to read

Each MaskType has different set of mask elements that are combined to form a mask expression. Based on the complexity and usage, mask types are classified as,

  1. Simple
  2. RegEx

Simple

The expressions that are generated with letters, digits, and special characters come under this group. This is mainly used for fixed length inputs. For example: Phone number.

Simple mask elements

Elements Description
0 Digit, required. This element accepts any single digit between 0 and 9.
9 Digit or space, optional.
# Digit or space, optional. Plus (+) and minus (-) signs are allowed.
L Letter, required. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-z A-Z] in regular expressions.
? Letter, optional. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-z A-Z]? in regular expressions.
C Character, optional.
A Alphanumeric, required.
< Shift down. Converts all the characters that follow to lowercase.
> Shift up. Converts all the characters that follow to uppercase.
<syncfusion:SfMaskedTextBox Width="200"
                            MaskType="Simple"
                            Mask="(000) 000-0000" />
SfMaskedTextBox maskedTextBox = new SfMaskedTextBox();
maskedTextBox.Width = "200";
maskedTextBox.MaskType = MaskedTextBoxMaskType.Simple;
maskedTextBox.Mask = "(000) 000-0000";

Mask type simple in WinUI Masked TextBox

RegEx

The expressions that are generated with regular expressions come under this group. For example: alpha numeric values [0-9A-Z].

RegEx mask elements

Elements Description
[ABC] Accepts any single character included in the specified set of characters.
[^ABC] Accepts any single character not included in the specified set of characters.
[0-9A-Z] Accepts any digit between 0-9 and character between A-Z.
\d Accepts any digit. Same as [0-9].
\D Accepts any non digit. Same as [^0-9].
\w Accepts any word character. \w is the same as [a-zA-Z_0-9].
\W Accepts any non word character. \W is the same as [^a-zA-Z_0-9].
\s Accepts any white space characters.
\S Accepts any non white space characters.
\S Accepts any non white space characters.
(?=ABC) Matches a group after the main expression without including it in the result.
(?!ABC) Specifies a group that cannot match after the main expression.
{n} Accepts the input for n number of times.
{n,} Accepts the input for 'n' and more than 'n' number of times.
{n,m} Accepts the input for n minimum number of times and m maximum number of times.
+ Accepts one or more matches for the preceding character.
* Accepts zero or more matches for the preceding character.
? Optional input (Zero or one occurrence of the matching input)
| Acts like a Boolean OR. Matches the expression before or after the |.
. Accepts any character. It can be changed based on culture
<syncfusion:SfMaskedTextBox MaskType="RegEx"
                            Width="200"
                            Mask="[A-Za-z0-9._%-]+@[A-Za-z0-9]+\.[A-Za-z]{2,3}" />
SfMaskedTextBox maskedTextBox = new SfMaskedTextBox();
maskedTextBox.Width = "200";
maskedTextBox.MaskType = MaskedTextBoxMaskType.RegEx;
maskedTextBox.Mask = "[A-Za-z0-9._%-]+@[A-Za-z0-9]+\.[A-Za-z]{2,3}";

Mask type RegEx in WinUI Masked TextBox