Formatting Value in .NET MAUI Masked Entry
5 Aug 20266 minutes to read
The SfMaskedEntry control allows you to format input values with prompt and literal characters defined in the mask expression by setting the ValueMaskFormat property. The default value of ValueMaskFormat is MaskedEntryMaskFormat.IncludePromptAndLiterals, which means the Value property of the control includes the characters typed by the user and any prompt or literal characters in the input.
The available formatting options are:
-
ExcludePromptAndLiterals- Returns only the characters typed by the user. -
IncludePrompt- Returns the typed characters and the prompt characters, but excludes the literal characters. -
IncludeLiterals- Returns the typed characters and the literal characters, but excludes the prompt characters. -
IncludePromptAndLiterals- Returns the typed characters, prompt characters, and literal characters.
Note: The
ValueMaskFormatproperty applies to theSimpleMaskType. When usingRegEx, the mask is treated as a regular expression and the formatting options do not apply.
Prerequisites
Before using the SfMaskedEntry, ensure the following NuGet package is installed in your .NET MAUI project:
Syncfusion.Maui.Inputs
For a step-by-step setup, refer to the Getting Started documentation.
Exclude prompts and literals
Configure the Masked Entry to exclude prompt and literal characters, preserving only the characters typed by the user. With this option, the resulting Value is DF321SD1A (the literals - and any unfilled prompt slots _ are removed).
<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
};
Include prompts
Configure the Masked Entry to preserve typed and prompt characters while excluding the literal characters. With this option, the resulting Value is DF321SD1A.
<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
};
Include literals
Configure the Masked Entry to keep typed and literal characters while excluding prompt characters. With this option, the resulting Value is DF321-SD1A .
<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
};
Include prompts and literals
Configure the Masked Entry to maintain typed, prompt, and literal characters in the input. This is the default option. The resulting Value is DF321-SD1A.
<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
};