Formatting value in .NET MAUI MaskedEntry

4 May 20256 minutes to read

The MaskedEntry control allows you to format input values with prompt and literal characters defined in the mask expression by setting the ValueMaskFormat property. By default, the Value property of the control includes the characters typed by the user and any prompt or literal characters in the input. The control provides several formatting options, which are listed as follows.

  1. ExcludePromptAndLiterals
  2. IncludePrompt
  3. IncludeLiterals
  4. IncludePromptAndLiterals

Exclude prompts and literals

Set up the MaskedEntry to exclude prompt and literal characters, preserving only the typed characters.

<editors:SfMaskedEntry x:Name="maskedEntry" WidthRequest="200"
                            MaskType="Simple"
                            ClearButtonVisibility="WhileEditing"
                            Mask=">AAAAA-AAAAA-AAAAA-AAAAA"
                            Value="DF321SD1A"
                            ValueMaskFormat="ExcludePromptAndLiterals"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry
{
    WidthRequest = 200,
    MaskType = MaskedEntryMaskType.Simple,
    ClearButtonVisibility = ClearButtonVisibility.WhileEditing,
    Mask = ">AAAAA-AAAAA-AAAAA-AAAAA",
    Value = "DF321SD1A",
    ValueMaskFormat = MaskedEntryMaskFormat.ExcludePromptAndLiterals
};

MAUI MaskedEntry excludes prompts and literals

Include prompts

Set up the MaskedEntry to preserve typed and prompt characters, excluding literals.

<editors:SfMaskedEntry x:Name="maskedEntry" WidthRequest="200"
                            MaskType="Simple"
                            ClearButtonVisibility="WhileEditing"
                            Mask=">AAAAA-AAAAA-AAAAA-AAAAA"
                            Value="DF321SD1A"
                            ValueMaskFormat="IncludePrompt"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry
{
    WidthRequest = 200,
    MaskType = MaskedEntryMaskType.Simple,
    ClearButtonVisibility = ClearButtonVisibility.WhileEditing,
    Mask = ">AAAAA-AAAAA-AAAAA-AAAAA",
    Value = "DF321SD1A",
    ValueMaskFormat = MaskedEntryMaskFormat.IncludePrompt
};

MAUI MaskedEntry includes prompts

Include literals

Keep typed and literal characters in the input but exclude prompt characters.

<editors:SfMaskedEntry x:Name="maskedEntry" WidthRequest="200"
                            MaskType="Simple"
                            ClearButtonVisibility="WhileEditing"
                            Mask=">AAAAA-AAAAA-AAAAA-AAAAA"
                            Value="DF321SD1A"
                            ValueMaskFormat="IncludeLiterals"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry
{
    WidthRequest = 200,
    MaskType = MaskedEntryMaskType.Simple,
    ClearButtonVisibility = ClearButtonVisibility.WhileEditing,
    Mask = ">AAAAA-AAAAA-AAAAA-AAAAA",
    Value = "DF321SD1A",
    ValueMaskFormat = MaskedEntryMaskFormat.IncludeLiterals
};

MAUI MaskedEntry includes literals

Include prompts and literals

Maintain typed, prompt, and literal characters in the input.

<editors:SfMaskedEntry x:Name="maskedEntry" WidthRequest="200"
                            MaskType="Simple"
                            ClearButtonVisibility="WhileEditing"
                            Mask=">AAAAA-AAAAA-AAAAA-AAAAA"
                            Value="DF321SD1A"
                            ValueMaskFormat="IncludePromptAndLiterals"/>
SfMaskedEntry maskedEntry = new SfMaskedEntry
{
    WidthRequest = 200,
    MaskType = MaskedEntryMaskType.Simple,
    ClearButtonVisibility = ClearButtonVisibility.WhileEditing,
    Mask = ">AAAAA-AAAAA-AAAAA-AAAAA",
    Value = "DF321SD1A",
    ValueMaskFormat = MaskedEntryMaskFormat.IncludePromptAndLiterals
};

MAUI MaskedEntry includes prompts and literals