> 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/captcha-validation.md).

# Captcha Validation

ReqEase offers flexible captcha validation options, allowing you to secure your forms and verify user interactions.

## **Default EasyCaptchaJS Configuration**

By default, ReqEase employs the [**EasyCaptchaJS**](https://github.com/HichemTab-tech/EasyCaptchaJS) captcha handler to add captcha validation to your forms. Here's the default configuration:

### **Default EasyCaptchaJS Configuration**

By default, ReqEase employs the [**EasyCaptchaJS**](https://github.com/HichemTab-tech/EasyCaptchaJS) captcha handler to add captcha validation to your forms. Here's the default configuration:

#### **Captcha Configuration Options**

* `captchaHandlersToRegister`: An array of captcha handlers, default options is null,it includes the default "easycaptchajs" handler.
* `captcha`: To activate captcha validation using the default handler, set this option to `true`.

{% hint style="warning" %}
Using the default captcha configuration you must implment the [**EasyCaptchaJS**](https://github.com/HichemTab-tech/EasyCaptchaJS) in your page/project. read more about it [here](https://github.com/HichemTab-tech/EasyCaptchaJS#installation).
{% endhint %}

### **Customizing Captcha Validation**

If you need to implement a different captcha solution or behavior, ReqEase offers customization through custom captcha handlers. Here's how you can tailor captcha validation to your specific needs:

1. **Create a Custom Captcha Handler**

   Develop your custom captcha handler by extending the `CaptchaHandler` class provided by ReqEase. Customize this handler to suit your captcha requirements.
2. **Register the Custom Handler**

   Register your custom captcha handler with a unique label in the `captchaHandlersToRegister` option. This label allows you to use your custom handler for captcha validation.

Here's an example of how you can create a custom captcha handler for ReqEase:

```javascript
import { CaptchaHandler } from '@reqease/reqease';

class CustomCaptchaHandler extends CaptchaHandler {
  // Register your custom captcha handler with a unique label
  label = 'customcaptcha';

  constructor(formValidator, captchaOptions) {
    super(formValidator, captchaOptions);
    // Additional setup specific to your custom captcha handler
  }

  init(ready) {
    // Initialize your custom captcha here
    // Call `ready` when your captcha is ready for validation
    ready();
  }

  triggerRequiredError() {
    // Handle error when captcha is required but not provided
  }

  // Implement other methods and behavior specific to your captcha
}
```

In this example, we've created a `CustomCaptchaHandler` class that extends `CaptchaHandler`. You can add your custom logic and behavior for captcha validation within this class.

To use this custom captcha handler, you would register it in your ReqEase configuration like this:

{% code title="ReqEase options" %}

```javascript
{
  // Other options
  captchaHandlersToRegister: CustomCaptchaHandler,
  captcha: {
    label: 'customcaptcha',
    // Other options required by your custom captcha handler
  },
}
```

{% endcode %}

By providing your custom handler's label in both `captchaHandlersToRegister` and the `captcha` option, ReqEase will use your custom captcha handler for captcha validation.

This allows you to implement and use your own captcha solution tailored to your specific requirements within ReqEase.

{% hint style="danger" %}
**Custom captcha handlers** feature is available when using ReqEase in a **module environment** (installed via npm or similar package manager). If you are using ReqEase via static script tags (CDN or local download), this feature may not be available. Please make sure you are using ReqEase in a module environment to utilize custom captcha handlers otherwise the default captcha handler will be applied.
{% endhint %}


---

# 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/captcha-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.
