Skip to main content
A newer version of this page is available. .

Data Validation in DevExpress Data Editors for .NET MAUI

  • 2 minutes to read

Data editors allow users to input different types of information: phone numbers, zip codes, email addresses, and so on. You can validate user input before it is committed to the underlying data object at your View Model level.

The following example validates editor input values when a user taps the Submit button on the page:

DevExpress Editors for MAUI

View Example

void OnSubmitClicked(Object sender, EventArgs e) {
    if (viewModel.Validate())
        DisplayAlert("Success", "Your account has been created successfully", "OK");
}
public bool Validate() {
    EmailHasError = string.IsNullOrEmpty(Email);
    LoginHasError = string.IsNullOrEmpty(Login);
    PasswordHasError = !CheckPassword();
    BirthDateHasError = BirthDate == null;
    PhoneHasError = Phone == null || Phone.Length != 10;
    NotesHasError = Notes.Length > 100;
    return !(NotesHasError || PhoneHasError || EmailHasError || LoginHasError || PasswordHasError);
}

Set an editor’s HasError property to true to indicate that the editor value contains an error. You can define alert hint text that notifies a user about errors. To do this, specify the EditBase.ErrorText property:

<dxe:TextEdit
    BoxMode="{Binding SelectedBoxMode}"
    StartIcon="face_black_24dp"
    Text="{Binding Login, Mode=TwoWay}"
    HasError="{Binding LoginHasError}"
    LabelText="Login"
    HelpText="*Required"
    ErrorText="Login is required"
    PlaceholderText="Enter login"/>

You can also use the DataFormView component to review and edit a business object’s properties. The component allows you to automatically create editors based on business object property types.

Note

As an alternative to standalone editors, you can use the DataFormView component to review and edit a business object’s properties. DataGridView ships with its own validation mechanisms you can use to validate user input. For more information, refer to the following help topic: Validate User Input in Data Form for .NET MAUI.

You can also use TextEdit‘s input masks to constrain user input. For more information, refer to the following section: Masked Input.