Skip to content

feat: add regex validation to custom text fields - #1

Open
intivalderas wants to merge 5 commits into
mainfrom
feat/text-field-regex-validation
Open

feat: add regex validation to custom text fields#1
intivalderas wants to merge 5 commits into
mainfrom
feat/text-field-regex-validation

Conversation

@intivalderas

Copy link
Copy Markdown
Owner

Summary

  • Adds an optional regex validation pattern to custom text fields, configurable via Settings → Data model → [Object] → [Text field]
  • A toggle in the field settings reveals a pattern input and an optional custom error message
  • Invalid values show a red border on the cell and a snackbar error when the user tries to save
  • Server-side validation also enforces the pattern on record create/update, with a user-friendly error message

Changes

twenty-shared

  • FieldMetadataSettings.ts — added validationPattern and validationErrorMessage to FieldMetadataTextSettings

twenty-server

  • validate-text-flat-field-metadata.util.ts (new) — validates the regex is syntactically valid on field save
  • flat-field-metadata-type-validator.service.ts — wired TEXT to the new validator
  • validate-text-field-or-throw.util.ts — enforces the pattern on record value save
  • data-arg-processor.service.ts — passes settings to the text validator

twenty-front

  • FieldMetadata.ts — extended FieldTextMetadata with validationPattern and validationErrorMessage
  • SettingsDataModelFieldTextForm.tsx — toggle + pattern/error message inputs with Zod client-side syntax validation
  • TextFieldInput.tsx — live red border feedback + snackbar error on invalid save attempt

Test plan

  • Create a custom text field, enable the validation toggle, enter ^BE0[0-9]{9}$ as pattern and Not a valid Belgian VAT number as error message, save
  • On a record, click the field and type an invalid value — red border should appear
  • Press Enter — save should be blocked and a snackbar error shown
  • Type a valid value (BE0123456789) — border clears, Enter saves successfully
  • Via API/GraphQL, attempt to set an invalid value — server should return the custom error message

🤖 Generated with Claude Code

@intivalderas
intivalderas force-pushed the feat/text-field-regex-validation branch from 82e0734 to 4212c83 Compare March 30, 2026 20:44
github-actions Bot and others added 4 commits March 31, 2026 00:23
Created by Github action

Co-authored-by: github-actions <github-actions@twenty.com>
Allows workspace admins to configure a regex pattern on any custom
text field. Values are validated both client-side (red border + snackbar
on save) and server-side (throws on record create/update).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@intivalderas
intivalderas force-pushed the feat/text-field-regex-validation branch from 2d198be to 36fc409 Compare March 30, 2026 22:36
- update universal-flat-field-metadata type-test for the new TEXT settings
  fields (validationPattern, validationErrorMessage) — fixes server typecheck
- name the field-in-error setter after its state to satisfy the
  matching-state-variable lint rule (fixes front lint)
- replace `(errors as any)` with typed react-hook-form error access
- translate default validation messages via t/msg instead of hardcoded
  English strings
- guard with isNonEmptyString and de-duplicate the regex check in
  TextFieldInput
- add unit tests for validateTextFieldOrThrow (pattern cases) and
  validateTextFlatFieldMetadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants