Back to Nocobase

Field validation

docs/docs/en/data-sources/data-modeling/collection-fields/validation.md

2.2.35.3 KB
Original Source

Field validation

To ensure collection accuracy, security, and consistency, NocoBase provides field validation. It has two parts: configuration rules and validation rules.

Configuration rules

NocoBase field rules integrate Joi. The supported rules are as follows.

String types

NocoBase Field interfaces corresponding to Joi string types include Input, Textarea, Phone, Email, URL, Password, and UUID.

Common rules

  • Minimum length
  • Maximum length
  • Length
  • Regular expression
  • Required

Email

View more options

URL

View more options

UUID

View more options

Number types

NocoBase Field interfaces corresponding to Joi number types include Integer, Number, and Percent.

Common rules

  • Greater than
  • Less than
  • Maximum value
  • Minimum value
  • Multiple

Integer

In addition to common rules, Integer fields support integer validation and unsafe-integer validation.

Number and Percent

In addition to common rules, Number and Percent fields support precision validation.

Date types

NocoBase Field interfaces corresponding to Joi date types include DateTime (with time zone), DateTime (without time zone), Date only, and Unix timestamp.

Supported validation rules are:

  • Greater than
  • Less than
  • Maximum value
  • Minimum value
  • Timestamp format validation
  • Required

Relation fields

Relation fields support required validation only. Note that required validation for relation fields is not currently supported in Subform or Subtable scenarios.

Apply validation rules

After you configure field rules, the corresponding validation rules are triggered when data is created or changed.

When a field is used in a form, its validation rules also appear in the field validation settings. They are displayed as read-only under Server-side field validation rules. To change these rules, return to Data source / Collection configuration and edit the field.

You can still add additional rules for the current form field under Client-side validation rules. These rules affect only the current field component. The validation rules that ultimately take effect combine Server-side field validation rules and Client-side validation rules.

Validation rules also apply to Subtable and Subform components:

Note that required validation for relation fields does not take effect in Subform or Subtable scenarios.

Difference between server-side field validation rules and client-side validation rules

Server-side field validation rules and client-side validation rules are configured in different places and have different scopes.

Configuration differences

  • Server-side field validation rules: Set field rules in Data source / Collection configuration. These rules are the base rules of the field
  • Client-side validation rules: Add additional rules in form-field settings. These rules affect only the current field component

Validation timing differences

  • Server-side field validation rules: Trigger client-side validation when the field is used in a form, and trigger validation before data is written. These rules also apply when data is created or changed through workflows, data import, and other paths
  • Client-side validation rules: Trigger client-side validation only in the current form field
  • Rule display: Server-side field validation rules are displayed read-only as inherited rules. Client-side validation rules are displayed separately and can be edited here
  • Error messages: Client-side validation rules support custom error messages. Server-side field validation rules do not currently support custom error messages