# Conditional & Cross-Field Validation

> Source: https://agilitycms.com/docs/developers/conditional-and-cross-field-validation

Agility content models support built-in field validation — required, length, and format constraints — plus **regular-expression validation** on a single field via the model's Advanced tab for precise format rules (emails, phone numbers, postal/zip codes, custom patterns). For logic that depends on **another field's value** — for example, "if Status is *Published*, then a Publish Date is required," or "End Date must be after Start Date" — validation is implemented with a **custom field app**: a developer-built field extension that has access to the item's values and enforces the conditional/cross-field rule. Agility does not use server-side "validation scripts"; per-field formatting is handled by regex, and anything beyond a single field is handled by a custom field app.

## Built-in, per-field validation

Standard model field settings cover the common cases:

- **Required** — the field must have a value.
- **Length** — minimum/maximum length constraints.
- **Format via regex** — on the field's **Advanced** tab, add a regular-expression pattern plus a custom validation message; the field then only accepts values matching the pattern. Useful for emails, phone numbers, URLs, postal codes, SKUs, and other structured formats.

These rules evaluate a single field in isolation and do not reference other fields.

## Conditional and cross-field validation (depends on another field)

When a rule must consider more than one field, it is implemented with a **custom field app** — a custom field/UI extension you build and register on the content model. Because the app renders a field within the editor and has access to the item's other field values, it can enforce conditional and cross-field rules and surface a validation message to the editor.

Typical cross-field / conditional patterns a custom field app can enforce:

- **Conditional requirement:** Field B is required only when Field A has a certain value (e.g. require *Redirect URL* only when *Type = External*).
- **Comparison across fields:** *End Date* must be after *Start Date*; *Discount Price* must be less than *Price*.
- **Mutually exclusive / dependent fields:** exactly one of two fields must be filled; or Field C is forbidden when Field D is set.
- **Aggregate/conditional constraints:** total of several numeric fields must not exceed a cap.

A worked custom-field-app example (e.g. End Date > Start Date) isn't published here; [contact Agility](https://agilitycms.com/contact-agility-cms) for current sample code and guidance.

## Choosing the right tool

| Need | Use |
| --- | --- |
| Single field required / length | Built-in field settings |
| Single field must match a format | Regex validation (Advanced tab) |
| Rule depends on another field's value | Custom field app |
| Rule depends on external data/service | Custom field app (calling your service from the app) |

## Shared responsibilities

| Area | Agility | Implementation partner / customer |
| --- | --- | --- |
| Built-in + regex validation | ✅ Provided in the content model UI | ✅ Configures patterns and messages |
| Cross-field / conditional validation | ✅ Provides the custom field app framework | ✅ Builds, tests, and maintains the custom field app |
| Editor experience of errors | ✅ Surfaces validation failures in the editor | ✅ Writes clear, actionable validation messages |
| Governance | — | ✅ Decides which rules are enforced and documents them for editors |

---

## Related pages

- [Content-first Approach](https://agilitycms.com/docs/developers/content-first.md)
- [Content Models](https://agilitycms.com/docs/developers/content-models.md)
- [Component Models ](https://agilitycms.com/docs/developers/component-models.md)
- [Fields](https://agilitycms.com/docs/developers/fields.md)
- [Nest, Link or Share? Choosing Linked Content Field Types](https://agilitycms.com/docs/developers/linked-content-field-types.md)
- [Getting Started with Linked Content](https://agilitycms.com/docs/developers/getting-started-with-linked-content.md)
- [Sitemaps](https://agilitycms.com/docs/developers/sitemaps.md)
- [Page Models](https://agilitycms.com/docs/developers/page-models.md)
- [Setting Up Preview](https://agilitycms.com/docs/developers/setting-up-preview.md)
- [Handling Agility URLs](https://agilitycms.com/docs/developers/handling-agility-urls.md)
- [Deployment & Code Repositories](https://agilitycms.com/docs/developers/deployment-code-repositories.md)
- [Tagging Content in Agility](https://agilitycms.com/docs/developers/tagging-content-in-agility.md)
- [Managing SEO for Developers](https://agilitycms.com/docs/developers/manging-seo-for-developers.md)
- [Mastering Nested Linked Content in Agility CMS: Enhance Hierarchical Data Management](https://agilitycms.com/docs/developers/nested-linked-content.md)
- [Advanced Field Validation with Regular Expressions](https://agilitycms.com/docs/developers/advanced-field-validation-with-regular-expressions.md)
- [Dynamic Content Control: Implementing Hide/When Formulas in Your Headless CMS Content Model](https://agilitycms.com/docs/developers/dynamic-content-control-implementing-hide-when-formulas-in-your-headless-cms-content-model.md)
- [Grouping Components into Tabs, Accordions, and Sections](https://agilitycms.com/docs/developers/grouping-components-into-tabs.md)
- [Set Up Web Studio with Any Framework](https://agilitycms.com/docs/developers/web-studio-setup-any-framework.md)
- [Troubleshooting Web Studio](https://agilitycms.com/docs/developers/troubleshooting-web-studio.md)
- [Content Modeling Anti-Patterns](https://agilitycms.com/docs/developers/content-modeling-anti-patterns.md)
- [Designing a Taxonomy That Scales](https://agilitycms.com/docs/developers/designing-a-taxonomy.md)
- [Map Your Design System to Component Models](https://agilitycms.com/docs/developers/design-system-to-component-models.md)
- [Structured Content Explained](https://agilitycms.com/docs/developers/structured-content-explained.md)
- [Beyond the Website: Apps, Kiosks, Email and In-App](https://agilitycms.com/docs/developers/beyond-the-website.md)
- [Make Your Content Model Agent-Friendly](https://agilitycms.com/docs/developers/agent-friendly-content-models.md)
- [Component Visibility (Private Beta)](https://agilitycms.com/docs/developers/component-visibility.md)

Index of every docs page: https://agilitycms.com/docs/llms.txt
