Calendar for WinForms | ComponentOne
DateEdit / Masking
In This Topic
    Masking
    In This Topic

    Masking is helpful in restricting user input in editors. In the DateEdit control, masking input allows entering input in a specific format. For instance, the DateEdit control should only accept numeric values or date and time values in a 24-hour format. To restrict users to input values in such formats, masking can be used in the DateEdit control.

    The following image shows the DateEdit control with masking applied in the edit mode.

    DateEdit allows masking input through the EditMask property. To enable masked input, set the EditMask property to a mask string comprising placeholders and literals. The control allows controlling other aspects of masked input through the MaskInfo property. It is also possible to define your own placeholders consisting of user-defined mask characters by using the CustomPlaceholders property. Note that masking does not work if the DateEdit control is in ReadOnly mode.

    The following table lists all placeholders and literals supported by DateEdit.

    Placeholder Description
    # Digit placeholder permits a numeric character or a plus or minus sign in this position (entry optional).
    . Decimal placeholder. The actual character used is the one specified as the decimal placeholder in your international settings. This character is treated as a literal for masking purposes.
    , Thousands separator. The actual character used is the one specified as the thousands separator in your international settings. This character is treated as a literal for masking purposes.
    : Time separator. The actual character used is the one specified as the time separator in your international settings. This character is treated as a literal for masking purposes.
    / Date separator. The actual character used is the one specified as the date separator in your international settings. This character is treated as a literal for masking purposes.
    \ Treat the next character in the mask string as a literal. This allows you to include the #, &, A, … characters in the mask. This character is treated as a literal for masking purposes.
    & Character placeholder (entry required). Any character is permitted.
    > Convert all the characters that follow to uppercase.
    < Convert all the characters that follow to lowercase.
    ~ Turns off the previous < or >.
    ! Causes the optional characters that follow in the edit mask to display from right to left, rather than from left to right. So, blanks appear on the left.
    ^ Turns off the previous ! character. After ^, blanks appear on the right.
    A Alphanumeric character placeholder (entry required). For example: a – z, A – Z, or 0 – 9.
    a Alphanumeric character placeholder (entry optional).
    0 Digit placeholder (entry required). For example: 0 – 9.
    9 Digit placeholder (entry optional).
    C Character or space placeholder (entry optional). Any character is permitted.
    L Letter placeholder (entry required). For example: a – z or A – Z.
    ? Letter placeholder (entry optional).
    \n New line literal. It is applicable when Multiline property is set to True.
    " All characters in a string enclosed in double quotes are considered as literals.
    Literal All other symbols are displayed as literals; that is, as themselves.

    The following code snippet shows how to set the EditMask property to apply masking in DateEdit.

    C#
    Copy Code
    // set the EditMask property to apply masking
    c1DateEdit1.EditMask = "00-LLL-9900";
    
    Note: The Masking topic is applicable for the DateEdit control in .NET 4.5.2 framework.