> For the complete documentation index, see [llms.txt](https://hichemtech.gitbook.io/reqease-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hichemtech.gitbook.io/reqease-docs/form-validation/custom-validations.md).

# Custom Validations

**ReqEase**'s **Form Validator** offers robust validation capabilities, allowing you to define custom validation logic tailored to your specific needs.

## Purpose

While **ReqEase** provides a rich set of built-in validation rules, there may be instances where you need to implement custom validation logic. Custom Validations empower you to do just that. These are JavaScript functions that you can define and attach to your form validation process.

## How Custom Validations Work

A Custom Validation is a JavaScript function that adheres to a specific signature:

```typescript
(callback: (validationSucceed: boolean) => void) => void
```

* The function takes a single argument, `callback`, which is another function.
* Inside your Custom Validation function, you implement your custom validation logic.
* Once your logic is executed, you call the `callback` function, passing it a boolean value indicating whether the validation succeeded (`true`) or failed (`false`).

Here's a simplified example of a Custom Validation function:

```javascript
function customValidationExample(callback) {
    // Custom validation logic
    const validationSucceed = /* Perform your custom validation checks here */;

    // Call the callback with the result
    callback(validationSucceed);
}
```

## Adding Custom Validations

To utilize Custom Validations in ReqEase, you need to add them to your **Form Validator** configuration. This is done using the [`customValidations`](/reqease-docs/reference/reference.md#customvalidation) option, where you provide an array of your Custom Validation functions.

Here's how you add Custom Validations to your Form Validator:

```javascript
const customValidationExample1 = function (callback) {
    // validation logic
    callback(true); //or false to indicate failure of validation.
};


// add Form Validator opions to reqEase Options:
const reqEase = new ReqEase({
        // Other options...
    validation: {
        // Other options...
        customValidations: [
            customValidationExample1,
            customValidationExample2,
            // Add more custom validations as needed
        ],
    }
});
```

## Executing Custom Validations

During the validation process, ReqEase iterates through your list of Custom Validations. For each Custom Validation, it executes the validation logic. If a Custom Validation fails (returns `false`), the overall validation process stops immediately, preventing any subsequent validations or form submissions. If all Custom Validations succeed, the validation continues.

Custom Validations offer a powerful and flexible way to extend ReqEase's validation capabilities, allowing you to implement complex, domain-specific validation logic. Whether you need to check complex business rules or validate user input against unique requirements, Custom Validations give you full control over your validation process.

<br>


---

# 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 dynamically by asking a question.

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

```
GET https://hichemtech.gitbook.io/reqease-docs/form-validation/custom-validations.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.
