DevExtreme v24.2 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

React Form - Validation

This demo shows how to validate Form editors. To apply validation rules to an editor, declare them in the validationRules array. Specify type and other properties for each rule.

To give you the ability to edit code on the fly, the demo uses SystemJS. For this reason, launching the demo takes some time. We strongly recommend that you do not use this approach in real projects.
Backend API

The following validation rules are shown in this demo:

  • RequiredRule
    Requires that a validated editor has a value.

  • CompareRule
    Compares the editor's value to the specified expression.

  • PatternRule
    Checks whether an editor value matches a specified pattern.

  • RangeRule
    Checks whether an editor value is in a specified range.

  • StringLengthRule
    Requires that an editor value length is in a specified range.

  • EmailRule
    Requires that an editor value matches the Email pattern.

  • AsyncRule
    Allows you to add custom server-side validation logic. Rules of this type run last, only if all other rules passed. In this demo, an AsyncRule checks whether user input matches test@dx-email.com.

  • CustomRule
    A rule with custom validation logic.

To submit form data, do the following:

  1. Wrap the Form component in the HTML <form> element.

  2. Use the Button Form Item to add a button to the form. This button submits the form data.

  3. Enable the button's useSubmitBehavior property.

When users click the button, the Form validates all editors that belong to the same validationGroup as this button. In this demo, all these editors belong to the customerData group. Form data can be submitted to a server only if input validation is successful. Enable the showValidationSummary property to display all validation errors at the bottom of the Form.

This demo also shows an implementation of the Reset button. When users click the button, it resets all Form data to initial values. The Form also uses the isDirty flag to check whether changes are made, and if not, disables the button.