# Discourse Authentication Validations

**URL:** https://meta.discourse.org/t/discourse-authentication-validations/292547
**Category:** Plugin
**Tags:** experimental
**Created:** [January 22, 2024, 7:32pm UTC](https://meta.discourse.org/t/discourse-authentication-validations/292547 "2024-01-22T19:32:52Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [January 22, 2024, 7:32pm UTC](https://meta.discourse.org/t/discourse-authentication-validations/292547/1 "2024-01-22T19:32:52Z")

</div>

| | | |
| --- | --- | --- |
| :discourse2: | **Summary** | **Discourse Authentication Validations** enables the ability to add custom validations to a User Field to toggle the display of User Fields on the Signup Modal. |
| 🛠 | **Repository Link** | [https://github.com/discourse/discourse-authentication-validations](https://github.com/discourse/discourse-authentication-validations) |
| 📖 | **Install Guide** | [How to install plugins in Discourse](https://meta.discourse.org/t/install-plugins-in-discourse/19157) |

# ℹ About

**Discourse Authentication Validations** adds the ability to add custom validations to a User Field.

Custom User Fields do not have any type of `validation` provided by core, outside of detecting an empty value on a required field. This plugin adds the ability to define a regex, per user field, that will then be checked against the provided input value.

Additionally, this plugin adds the ability to toggle the display of User Fields on the Signup Modal. This allows you to _“chain”_ User Fields together, so that a User Field is only displayed if a previous User Field has a specific value.

# 🏗 Basic Setup

### 1. Enable Plugin

The Discourse Authentication Validations plugin can be enabled either by the toggle or from its settings, both accessible from your `admin/plugins` page.

### 2. Add a custom validation to a User Field

After the Discourse Authentication Validations plugin has been enabled you will see a Include a Custom Validations checkbox at the bottom of your User Field form.

 ![Screenshot 2024-07-08 at 2.07.04 PM](https://global.discourse-cdn.com/meta/original/4X/2/b/7/2b727af4b5730bd6e1d4dfa491c22a4dc127e936.png)

When checked it will display an additional three fields:

1. Value Validation Regex
2. Show Values
3. Target User Fields

 ![Screenshot 2024-07-08 at 2.06.12 PM](https://global.discourse-cdn.com/meta/original/4X/d/a/e/dae5f4c84235fdb35ad823c6a726ca72fd69856b.png)

# 🔐 Adding a Custom Validation

Include a valid regex in the `Value Validation Regex` field:

 ![Screenshot 2024-06-05 at 11 18 20 PM](https://global.discourse-cdn.com/meta/original/4X/c/5/f/c5f075689fe7a21b6686d7f93edd54dd25d31472.png)

The user field’s value on the signup form will now be tested against the regex you have included. In the case that the input does not meet the standards of your custom Regex, the signup form will not submit.

_No value (relies on default form validation)_

 ![Screenshot 2024-06-05 at 11 07 04 PM](https://global.discourse-cdn.com/meta/original/4X/e/d/4/ed42a8dbe6622c51082b1685b78749829d942109.png)

_Incorrect value_

 ![Screenshot 2024-06-05 at 11 07 40 PM](https://global.discourse-cdn.com/meta/original/4X/f/1/0/f10adb847f1c4e9ef84fab6072ceace9e96f3080.png)

_Correct value_

 ![Screenshot 2024-06-05 at 11 08 02 PM](https://global.discourse-cdn.com/meta/original/4X/8/8/a/88ab59f29b1dd7e7cbcbe5275afacfc606a8072f.png)

# 🔗 Chaining User Fields

Firstly, include a `Show Values` value on a User Field.

When a User Field has a `Show Values` value included it will watch the value of the attached input until the input value matches **ANY** of the `show values`. It will then toggle the visibility of any included `Target User Fields`, making them visible.

 ![Screenshot 2024-01-22 at 12.30.15 PM](https://global.discourse-cdn.com/meta/original/4X/1/2/5/125844390b75dcb36aae52bf882c355dea481abe.png)

> [@](#):
>
> **Hint** 🏅
> 
> If include the value `null` (case sensitive) then the attached `Target User Fields` will be visible by default, but if a new value is selected that is not included in `Show Values` it will be hidden.

Secondly, add a `Target User Fields` value.

In the `Target User Fields` dropdown you will see a list of all available User Fields. Any User Field you select will have their visibility toggled by corresponding values in `Show Values`.

 ![Screenshot 2024-01-22 at 12.31.49 PM](https://global.discourse-cdn.com/meta/original/4X/e/b/2/eb28e466165f4cc57406b016b5e1548646a07f54.png)

# 🛠 Advanced Chaining

You can chain User Fields together by adding custom validations to multiple User Fields.

For example, let’s say we have three User Fields with the given values:

| Name | Has Custom Validation | Show Values | Target User Fields |
| --- | --- | --- | --- |
| Input One | true | show-field-two | Input Two |
| Input Two | true | show-field-three | Input Three |
| Input Three | false | | |

Input Two and Three will be hidden by default as they are _“children”_ of Input One. When the `show value` of `show-field-two` is added to Input One, Input Two will be displayed, but Input Three will still remain hidden. It will remain hidden until Input Two has the value of `show-field-three`.

With the correct combination of Show Values and Target Classes you can infinitely _nest_ User Fields beneath each other.

---

_[View the full topic](https://meta.discourse.org/t/discourse-authentication-validations/292547)._
