Skip to main content

Mask Editing

  • 2 minutes to read

The DevExpress editors allow you to use masks during editing. Masks are useful when a string entered by an end-user into an editor matches a specific format. For instance, a text editor that accepts date/time values in the 24-hour format only, or only numeric values, or a phone number that only allows an end-user to enter digits into automatically constructed placeholders.

Within the MVC Editors components, masked input is supported by the following editor types.

  • Text box editors (in particular, the TextBox and ButtonEdit).

    Mask settings can be accessed via the TextBoxProperties.MaskSettings (ButtonEditProperties.MaskSettings) property. The editor’s mask can be specified via the MaskSettings.Mask property.

    This example demonstrates how you can define mask editing settings for the TextBox MVC extension.

    The image below shows the result:

    TextBox_MaskEditing

    View code (Razor):

    @Html.DevExpress().TextBox(
        settings => {
            settings.Name = "textBox1";
            settings.Width = 170;
            settings.Properties.MaskSettings.Mask = "+1 (999) 000-0000";
            settings.Properties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.None;
        }).GetHtml()
    
  • Date editors (DateEdit).

    To enable masked input in a date editor, the DateEditProperties.UseMaskBehavior property should be set to true. The mask can be defined via the DateEditProperties.EditFormatString property, if the DateEditProperties.EditFormat property is set to EditFormat.Custom.

    This example demonstrates how you can define mask editing settings for the DateEdit MVC extension.

    The image below shows the result:

    DateEdit_MaskEditing

    View code (Razor):

    @Html.DevExpress().DateEdit(
        settings => {
            settings.Name = "dateEdit1";
            settings.Properties.UseMaskBehavior = true;
            settings.Properties.EditFormat = EditFormat.Custom;
            settings.Properties.EditFormatString = "MMMM dd, yyyy";
            settings.Properties.DisplayFormatString = "MMMM dd, yyyy";
            settings.Date = DateTime.Now;
            settings.PopupCalendarOwnerName = "dateEdit1";
        }).GetHtml()
    

Note

Defining a text box editor’s mask via the editor’s MaskSettings.Mask property automatically activates the editor’s built-in validation functionality. This might affect the editor’s appearance, because some extra space might be occupied for an error image and text to be displayed for invalid input, which is due to an editor’s default validation settings. To customize the editor appearance in this case, use validation properties available via the editor’s ValidationSettings property (for instance, you can modify the ValidationSettings.Display or ValidationSettings.ErrorDisplayMode property, etc). You can also provide a mask-specific error text via the MaskSettings.ErrorText property of an editor.

Concepts

The following topics are available within the ASPxEditors Mask Editing section and describe mask editing concepts.