Back to Devexpress

MaskSettings.Mask Property

aspnet-devexpress-dot-web-dot-masksettings.md

latest7.4 KB
Original Source

MaskSettings.Mask Property

Gets or sets a mask expression.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue("")]
public string Mask { get; set; }
vb
<DefaultValue("")>
Public Property Mask As String

Property Value

TypeDefaultDescription
StringString.Empty

A string representing a mask expression.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to Mask
ASPxButtonEdit

.MaskSettings .Mask

| | ASPxTextBox |

.MaskSettings .Mask

| | ButtonEditProperties |

.MaskSettings .Mask

| | TextBoxProperties |

.MaskSettings .Mask

|

Remarks

Applying a mask to the editor restricts the text that end-users can enter. If masked mode is enabled, the editor validates the text against the mask, and only allows data that satisfies the mask expression to be entered. To enable masked mode for an editor, specify the mask using the Mask property.

Note

Example

  • Zip code

aspx
<dx:ASPxTextBox ID="txtZip" runat="server">
    <MaskSettings Mask="00000" PromptChar="#" />
</dx:ASPxTextBox>
  • Phone Number

aspx
<dx:ASPxTextBox ID="txtPhone" runat="server">
    <MaskSettings Mask="+1 (999) 000-0000" IncludeLiterals="None" />
</dx:ASPxTextBox>
  • Price

aspx
<dx:ASPxTextBox ID="txtPrice" runat="server" >
    <MaskSettings Mask="$<0..99999g>.<00..99>" IncludeLiterals="DecimalSymbol" />
</dx:ASPxTextBox>
  • Date

aspx
<dx:ASPxDateEdit ID="dateEdit" runat="server" EditFormat="Custom" 
UseMaskBehavior="true" EditFormatString="MMMM dd, yyyy" >
</dx:ASPxDateEdit>
  • Promo Code

aspx
<dx:ASPxTextBox ID="txtPromoCode" runat="server" >
    <MaskSettings ShowHints="true" Mask="<HOME|*BUSINESS>->aaaa-aaaa" />
</dx:ASPxTextBox>

MVC:

csharp
@Html.DevExpress().TextBox(settings => {
    settings.Name = "textBox3";
    settings.Width = Unit.Percentage(100);
    settings.Properties.MaskSettings.Mask = "+1 (999) 000-0000";
    settings.Properties.MaskSettings.IncludeLiterals = MaskIncludeLiteralsMode.None;
    settings.Properties.MaskSettings.ErrorText = "Invalid Phone Number";
    settings.Properties.ValidationSettings.Display = Display.Dynamic;
}).GetHtml()

Concepts

Online Demos

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Mask property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-how-to-dynamically-change-mask-settings-based-on-the-current-object/CS/ChangeEditMask.Module.Web/Controllers/WebChangeMaskController.cs#L17

csharp
case BusinessObjects.EditMask.Date:
    textEdit.MaskSettings.Mask = "MM/dd/yyyy";
    break;

xaf-how-to-dynamically-change-mask-settings-based-on-the-current-object/VB/ChangeEditMask.Module.Web/Controllers/WebChangeMaskController.vb#L16

vb
Case BusinessObjects.EditMask.Date
    textEdit.MaskSettings.Mask = "MM/dd/yyyy"
Case BusinessObjects.EditMask.Time

See Also

PromptChar

ErrorText

ShowHints

IncludeLiterals

Mask

MaskSettings Class

MaskSettings Members

DevExpress.Web Namespace