# Applying validation

Once we have both [validation rules](/react-advanced-form/getting-started/validation-rules.md) and [messages](/react-advanced-form/getting-started/validation-messages.md) defined, we can to apply them to see the working result.

There are multiple ways to apply the validation to the forms in our application. Either of them are suitable in different situations.

## Application-wide

We can use a `FormProvider` component to apply the validation rules and message application-wide. That implies that all the forms in the application abide by the defined rules, which is what you want in most of the cases.

Render a `FormProvider` on the root level of your application, close to other providers you may have (for example, from Redux or Apollo).

```jsx
// app/index.js
import React from 'react'
import ReactDOM from 'react-dom'
import { FormProvider } from 'react-advanced-form'
import validationRules from './validation-rules'
import validationMessages from 'validation-messages'

const App = () => (
  <FormProvider rules={validationRules} messages={validationMessages}>
    <Root />
  </FormProvider>
)

ReactDOM.render(<App />, document.getElementById('root'))
```

## Form-wide

A validation schema can be applied to a specific form. By doing so, it can [extend or override](/react-advanced-form/validation/schema.md#extending-a-schema) the application-wide schema on demand.

```jsx
import React from 'react'
import { Form } from 'react-advanced-form'

const validationRules = {
  extend: false, // when "true", merges custom- and application rules together
  type: {
    password: ({ value }) => anotherValidator(value),
  },
}

const validationMessages = {
  type: {
    password: {
      invalid: 'I am different than general invalid password message',
    },
  },
};

export default class ExampleForm extends React.Component {
  render() {
    return (
      <Form rules={validationRules} messages={validationMessages}>
        {/* ... */}
      </Form>
    )
  }
}
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://redd.gitbook.io/react-advanced-form/getting-started/applying-validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
