Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Implement a Custom Validation Procedure

The following example shows how to handle the BaseEdit.Validate event to implement a custom validation procedure.

The image below shows the result:

exDataValidation

<dxe:TextEdit x:Name="dxTextEdit"
          ValidateOnTextInput="False"
          Validate="dxTextEdit_Validate"/>
private void dxTextEdit_Validate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e) {
    // e.Value - the processed input value
    if (e.Value == null) return;
    if (e.Value.ToString().Length > 4) return;
    // Set the e.IsValid property to 'false' if the input value is invalid
    e.IsValid = false;
    // Specifies the error icon type
    e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information;
    // Specifies the error text
    e.ErrorContent = "User ID is less than five symbols. Please correct.";
}