This repository contains sample for how to perform email validation using the .NET MAUI SfMaskedEntry control This section demonstrates how to perform email validation in the .NET MAUI MaskedEntry (SfMaskedEntry). We can use the Valuechanged event to validate the email in SfMaskedEntry.
Step1:XAML Set Up
Create the MaskedEntry control in the XAML markup and configure it with the required properties. Specifies the event handler maskedEntry_ValueChanged to handle the ValueChanged event of the SfMaskedEntry control.
<inputs:SfMaskedEntry x:Name="maskedEntry"
MaskType="RegEx"
Mask="[A-Za-z0-9._%-]+@[A-Za-z0-9]+\.[A-Za-z]{2,3}"
WidthRequest="200"
ValueChanged="maskedEntry_ValueChanged"
ValidationMode=”LostFocus”>
</inputs:SfMaskedEntry>
Step2: C# Set Up
In ValueChanged event, add the condition to validate the email as per the following demonstration. HasError checks if the sfmaskedEntry currently has an error based on the defined Mask. If HasError is true you can handle invalid input cases. IsMaskedCompleted Indicates whether the current input matches the full Mask pattern specified. If IsMaskedCompleted is true, it means the input is valid according to the mask pattern. Here you can perform your logic for validation.
private void maskedEntry_ValueChanged(object sender, MaskedEntryValueChangedEventArgs e)
{
SfMaskedEntry maskedEntry = sender as SfMaskedEntry;
if (maskedEntry.HasError)
{
// Execute when validation is not completed
}
if (e.IsMaskCompleted)
{
// Execute when validation is completed
// Perform your logic
}
}
Output