> For the complete documentation index, see [llms.txt](https://coldbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox.ortusbooks.com/ecosystem/validation.md).

# Validation

Server-side validation for ColdBox applications with the cbvalidation module — constraints, results, and handler integration.

ColdBox provides server-side validation through the **cbvalidation** module: a unified engine for validating objects, structs, and forms with declared constraints.

```bash
box install cbvalidation
```

📖 **Full documentation:** [cbvalidation.ortusbooks.com](https://cbvalidation.ortusbooks.com)

## Quick Example

Declare constraints on a class, then validate it anywhere:

{% tabs %}
{% tab title="BoxLang" %}

```javascript
// models/User.bx
class {

    constraints = {
        "email"    : { required : true, type : "email" },
        "password" : { required : true, size : "8..64" }
    }

    property name="email"
    property name="password"
}
```

{% endtab %}

{% tab title="CFML" %}

```javascript
// models/User.cfc
component {

    this.constraints = {
        "email"    : { required : true, type : "email" },
        "password" : { required : true, size : "8..64" }
    }

    property name="email"
    property name="password"
}
```

{% endtab %}
{% endtabs %}

```javascript
// In a handler or service
property name="validationManager" inject="ValidationManager@cbvalidation";

function save( event, rc, prc ){
    var user   = populateModel( "User" )
    var result = validationManager.validate( target : user )

    if ( result.hasErrors() ) {
        return event.renderData(
            type       : "json",
            data       : { "errors" : result.getAllErrors() },
            statusCode : 422
        )
    }

    userService.save( user )
    event.renderData( type : "json", data : user.getMemento(), statusCode : 201 )
}
```

The result object gives you `hasErrors()`, `getAllErrors()`, `getError( field )`, and locale-aware messages via `cbi18n`.

## When to Use It

* Validating incoming `rc` data before it reaches your models
* Validating ORM/Quick entities before persistence
* Reusing the same constraint set across handlers, services, and APIs

ColdBox's `populateModel()` and event handler [model data binding](/the-basics/event-handlers/model-integration/model-data-binding.md) pair naturally with cbvalidation — populate first, validate second.

## Alternatives

* **RuleBox** (`box install rulebox`) — when your validation is really a business-rules decision tree rather than field constraints
* Native engine validation (`isValid()`) — fine for one-off checks, but doesn't scale to constraint sets

## See Also

* [Event Handler Validation](/the-basics/event-handlers/validation.md)
* [Model Data Binding](/the-basics/event-handlers/model-integration/model-data-binding.md)
* [i18n](/ecosystem/i18n.md) — localized validation messages


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox.ortusbooks.com/ecosystem/validation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
