Mask Type: Simple

  • 5 minutes to read

This document describes the syntax for creating masks of the Simple mask type. These masks are quite plain and therefore they do not allow you to implement sophisticated data input patterns. They can however be useful when an editor should accept a string that has a fixed format and is of a fixed length (for instance, a phone number, zip code, etc).

For general information on the other masked modes refer to the Mask Types document.

Simple Mask Mode

To enable the Simple mask type, set the editor's TextEdit.MaskType (or the TextEditSettings.MaskType for the in-place editors) property to MaskType.Simple. The mask itself should be specified via the TextEdit.Mask (or TextEditSettings.Mask) property.

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

Metacharacters

Metacharacters are used to represent a range of symbols. An end user can enter text only in the positions which correspond to metacharacters. When a metacharacter is found at 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 Meaning
L An L character requires an alphabetical character in this position. For the U.S. this is A-Z, a-z.
l An l character permits only an alphabetical character in this position, but doesn't require it.
A An A character requires an alphanumeric character in this position. For the U.S. this is A-Z, a-z, 0-9.
a An a character permits only an alphanumeric character in this position, but doesn't require it.
C A C character requires an arbitrary character in this position.
c A c character permits an arbitrary character in this position, but doesn't require it.
0 A 0 character requires a numeric character in this position.
9 A 9 character permits only a numeric character in this position, but doesn't require it.
# A # character permits only a numeric character or a plus or minus sign in this position, but doesn't require it.

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 Meaning
> If a > character appears in the mask, all the characters that follow it are converted to 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 converted to lowercase until the end of the mask or until a > character is encountered.
<> If these two characters appear together in a mask, no case checking is performed and the data is formatted with the case used by the end-user during data entry.
/ A / character is used to separate the months, days, and years in dates. If the character that separates the 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 the hours, minutes, and seconds in time values. If the character that separates the hours, minutes, and seconds is different in the regional settings of the system that the application runs on that character will be used instead.
$ A $ character is used to designate currency values. If the character that designates the 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 that is neither a metacharacter nor a special character is called a literal. Literals are inserted automatically as is into the edit box in their positions defined by the mask. An end user has no need to enter literal characters. The cursor skips over them during editing.

The metacharacters and special characters can also appear as literal characters if they are preceded by a backslash (\).

Examples

  1. A mask for entering a telephone number: (000)000-00-00.

    Each '0' metacharacter in this mask requires a numeric character in the corresponding position. No characters can be omitted. The -, ( and ) characters in the mask are literals.

    The following are images of an editor that uses this mask:

    CD_Mask_Simple_phone_empty (a value is not entered)

    CD_Mask_Simple_phone (a value is entered)

  2. A mask for entering a telephone number with an optional area code: (999)000-00-00

    Here the 9 metacharacter allows end-users to omit the area code part of a phone number.

    CD_MaskOverview_Simple_phone (a valid phone number without a code part)

  3. A mask for entering an alpha-numeric sequence: \A>LL-00

    Here \A stands for the literal character A. Since A is used as a metacharacter the backslash must be used to make A appear as a literal. The > command specifies that the following text should be in uppercase. The LL substring indicates that two alphabetical characters should be inserted in this position. The 00 substring is a placeholder for two digits.

    CD_Mask_Simple_alpha_empty (a value is not entered)

    CD_Mask_Simple_alpha (a value is entered)