|
| 1 | +# Field Validation |
| 2 | +To ensure data accuracy,security and consistency in data tables, NocoBase provides field validation functionality. This feature consists of two main parts: rule configuration and validation rule apply. |
| 3 | + |
| 4 | +## Rule Configuration |
| 5 | + |
| 6 | + |
| 7 | +NocoBase system fields integrate [Joi](https://joi.dev/api/) rules, with support as follows: |
| 8 | + |
| 9 | +### String |
| 10 | +Joi string types correspond to the following NocoBase field types: single line text, long text, phone, email, URL, password, UUID. |
| 11 | +#### Common Rules |
| 12 | +- Min length |
| 13 | +- Max length |
| 14 | +- Length |
| 15 | +- Pattern |
| 16 | +- Required |
| 17 | + |
| 18 | +#### Email |
| 19 | + |
| 20 | +[View more options](https://joi.dev/api/?v=17.13.3#stringemailoptions) |
| 21 | + |
| 22 | +#### URL |
| 23 | + |
| 24 | +[View more options](https://joi.dev/api/?v=17.13.3#stringurioptions) |
| 25 | + |
| 26 | +#### UUID |
| 27 | + |
| 28 | +[View more options](https://joi.dev/api/?v=17.13.3#stringguid---aliases-uuid) |
| 29 | + |
| 30 | +### Number |
| 31 | +Joi number types correspond to the following NocoBase field types: integer, number, percentage. |
| 32 | +#### Common Rules |
| 33 | +- Greater than |
| 34 | +- Less than |
| 35 | +- Max value |
| 36 | +- Min value |
| 37 | +- Multiple |
| 38 | + |
| 39 | +#### Integer |
| 40 | +In addition to common rules, integer fields additionally support [integer validation](https://joi.dev/api/?v=17.13.3#numberinteger) and [unsafe integer validation](https://joi.dev/api/?v=17.13.3#numberunsafeenabled). |
| 41 | + |
| 42 | + |
| 43 | +#### Number & Percent |
| 44 | +In addition to common rules, number and percentage fields additionally support [precision validation](https://joi.dev/api/?v=17.13.3#numberinteger). |
| 45 | + |
| 46 | + |
| 47 | +### Date |
| 48 | +Joi date types correspond to the following NocoBase field types: date (with timezone), date (without timezone), date only, Unix timestamp. |
| 49 | + |
| 50 | +Supported validation rules: |
| 51 | +- Greater than |
| 52 | +- Less than |
| 53 | +- Max value |
| 54 | +- Min value |
| 55 | +- Timestamp |
| 56 | +- Required |
| 57 | + |
| 58 | +### Association Fields |
| 59 | +Association fields only support required validation. Note that required validation for association fields is currently not supported in sub-form or sub-table scenarios. |
| 60 | + |
| 61 | + |
| 62 | +## Validation Rule Apply |
| 63 | +After configuring field rules, the corresponding validation rules will be triggered when adding or modifying data. |
| 64 | + |
| 65 | + |
| 66 | +Validation rules also apply to sub-table and sub-form components: |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +Note that in sub-form or sub-table scenarios, required validation for relationship fields does not take effect. |
| 72 | + |
| 73 | + |
| 74 | +## Differences from Client-Side Field Validation |
| 75 | +[Client-side field validation](/handbook/ui/fields/field-settings/validation-rules) and server-side field validation are applied in different scenarios, with significant differences in implementation and rule trigger timing, so they need to be managed separately. |
| 76 | + |
| 77 | +### Configuration Method Differences |
| 78 | +- **Client-side validation**: Configure rules in edit forms (as shown in the figure below) |
| 79 | +- **Server-side field validation**: Set field rules in Data Source → Collections Configuration |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +### Validation Trigger Timing Differences |
| 87 | +- **Client-side validation**: Triggers validation in real-time as users fill in fields, displaying error messages immediately |
| 88 | +- **Server-side field validation**: Validates on the server side before data entry after data submission, with error messages returned through API responses |
| 89 | +- **Application scope**: Server-side field validation takes effect not only during form submission but also triggers in all scenarios involving data addition or modification, such as workflows and data imports |
| 90 | +- **Error messages**: Client-side validation supports custom error messages, while server-side validation does not currently support custom error messages |
0 commit comments