[**Documentation**](../../../README)

***

[Documentation](../../../README) / [zerotal](../../README) / [validator](../README) / validate

# Function: validate()

> **validate**\<`S`\>(`ctx`, `factory`): `Promise`\<[`Infer`](../type-aliases/Infer)\<`ExtractDefs`\<`S`\>\>\>

Defined in: [packages/validator/src/validate.ts:28](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/validator/src/validate.ts#L28)

Validate the HTTP request body against the given schema.

On success: returns the validated, typed data object (only schema fields).
On failure (Inertia or web form): stores errors in session + throws
  ValidationRedirectError → global handler converts to 303 redirect.
On failure (JSON API): throws ValidationJsonError → global handler → 422.

## Type Parameters

### S

`S` *extends* `Record`\<`string`, [`FieldRule`](../interfaces/FieldRule)\>

## Parameters

### ctx

[`HttpContext`](../../index/classes/HttpContext)

### factory

(`rules`) => `S`

## Returns

`Promise`\<[`Infer`](../type-aliases/Infer)\<`ExtractDefs`\<`S`\>\>\>
