# Form Validation

*Article Topics:* [*Sites*](/getting-started/common-topics/sites.md)*,* [*Templates*](/getting-started/common-topics/templates.md)*,* [*Tours*](/getting-started/common-topics/tours.md)

## Form Inputs

NATS forms have built-in validation checks on form fields. These require that the form be submitted for NATS to validate them.&#x20;

For example, on the join form, you will see that the input names have the following structure:\
\&#xNAN;*signup\[username:1:6:16:::username\_check]*

"signup\[]" is the array that contains all submitted inputs. The format for each is:

1. name of the input - In this example: the username
2. required flag - If set to 1, this input must be submitted
3. minimum - the minimum length of the input
4. maximum - the maximum length of the input
5. compare - you can specify another input name here to compare the values. If set, the two input values must match
6. session compare - you can specify a session variable name here to compare to the input value. If set, the input value must match the session variable's value
7. special check - you can specify a check function, or multiple check functions (separated by a comma) for NATS to run on the input.

## Check Functions

The available check functions are detailed below. Some allow you to pass additional arguments to customize the behavior of the check function.

### username\_check

This function will check that the input only consists of characters and numbers and starts with a character.

<figure><img src="/files/jN6dwjMivEvGchM3JuWO" alt=""><figcaption></figcaption></figure>

### username\_check\_detailed

You can set detailed limitations on usernames by passing arguments to the special check function.&#x20;

For example: *\[username:1:6:16:::username\_check\_detailed;1|4|9|||]*

The details after the "username\_check\_detailed;" separated by a pipe "|" define the arguments:

1. (Flag 1 or 0) - Defines whether or not the first character MUST be a letter
2. (Numeric) - Defines the minimum number of uppercase characters there needs to be
3. (Numeric) - Defines the minimum number of lowercase characters there needs to be
4. (Numeric) - Defines the minimum amount of Numbers (0-9) there needs to be
5. (Flag 1 or 0) - Defines whether or not all characters MUST be upper case (This overrides the numeric lower case check)
6. (Flag 1 or 0) - Defines whether or not all characters MUST be lowercase (This overrides the numeric uppercase check)<br>

Using the same example above; *\[username:1:6:16:::username\_check\_detailed;1|4|9|||]*

The limitations set for the Username are:

1. The first character must be a letter
2. There must be at least 4 uppercase letters
3. There must be at least 9 lowercase

### password\_check

This function will check that the input only consists of characters and numbers.

<figure><img src="/files/Ukul2E2tTM0wCTvgx4wW" alt=""><figcaption></figcaption></figure>

### password\_check\_detailed

You can set detailed limitations on passwords by passing arguments to the special check function.&#x20;

For example: *\[password:1:6:16:::password\_check\_detailed;1|||5|3|1|]*

The details after the "password\_check\_detailed;" separated by a pipe "|" define the arguments:

1. (Flag 1 or 0) - Defines whether or not the first character MUST be a letter.
2. (Numeric) - Defines the minimum number of uppercase characters there needs to be.
3. (Numeric) - Defines the minimum number of lowercase characters there needs to be.
4. (Numeric) - Defines the minimum number of Numbers (0-9) there needs to be.
5. (Numeric) - Defines the minimum number of Special Characters there needs to be (Anything that is not a letter or a number).
6. (Flag 1 or 0) - Defines whether or not all characters MUST be upper case (This overrides the numeric lower case check).
7. (Flag 1 or 0) - Defines whether or not all characters MUST be lowercase (This overrides the numeric uppercase check).

Using the same example above; *\[password:1:6:16:::password\_check\_detailed;1|||5|3|1|]*

The limitations set for the Password are:

1. The first character must be a letter
2. There must be at least 5 Numeric Characters
3. There must be at least 3 Special Characters
4. Any Alphabetic characters must be uppercase

### email\_check

Checks the input using a regular expression to determine if it is a valid email. This function does not perform domain checking.

<figure><img src="/files/OU6TFzoi5NdvhHFpgUJo" alt=""><figcaption></figcaption></figure>

### strong\_email\_check

You can add the check "strong\_email\_check" to have the domain of the email (everything after the @) checked for MX records using the PHP function getmxrr: [https://php.net/manual/en/function.getmxrr.php](http://php.net/manual/en/function.getmxrr.php)

{% hint style="danger" %}
**Please Note:** If you are using this check, you will want to ensure the "dns-search" directive on your server is turned off. This can create issues with the function called in this check.
{% endhint %}

### substring\_check

This check takes another input name as an argument.&#x20;

For example: *signup\[password:1:6:16:::password\_check,substring\_check;username]*&#x20;

In the above example, the password input will have the normal password\_check run, then it will do the substring\_check to ensure the password does not have a part that matches the username input.

### url\_check

Checks that the input is a valid URL.

### not\_numeric\_check

Checks if the input contains any numbers.

### alnum\_check

Ensures input only consists of alphanumeric characters and underscores.

### alnum\_space\_check

Ensures input only consists of alphanumeric characters, underscores, and spaces.

### alnum\_letter\_check

Ensures input only consists of alphanumeric characters and underscores, and starts with a character.

### alnum\_letter\_space\_check

Ensures input only consists of alphanumeric characters, underscores, spaces, and starts with a character.

### age\_check

The input for this check must be a date in the format of:

Y-m-d (1985-05-13)

The function will take this input as the birth date and compare the date to now, to determine the age of the user. The function will then compare the resulting age to your configuration setting "$config\['MIN\_AGE']".&#x20;

If the age of the user is less than the configuration, NATS will return an error:

"You have to be at least $config\[MIN\_AGE] years old to join!"

### mod10\_check

Uses the mod10 algorithm to check for a valid credit card numb.


---

# 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://docs.toomuchmedia.com/nats-admin/sites/further-reading/form-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.
