# Input Validation

CommandPrompter's input validation uses regex to check for the input. To use it, you have to define an `input validator` in the `prompt-config.ym` under the key `Input-Validation` and use it as a `prompt argument` for your `prompt`

#### Input Validator

An input validator could have any key. But under that key, there must be an `Alias` and at least one[#validator](#validator "mention"). There's also an optional key that you can set called `Err-Message`. The following is an example of input validators that's included with CommandPrompter by default.

#### Validators

| Validator     | Key           | Description                                                                    |
| ------------- | ------------- | ------------------------------------------------------------------------------ |
| Regex         | Regex         | validates an input by checking if it matches the defined regular expression    |
| Online Player | Online-Player | validates an input by checking if it's a username of one of the online players |

```yml
Input-Validation:
  Integer-Sample:
    Alias: is
    Regex: '^\d+'
    Err-Message: '&cPlease enter a valid integer!'
  Alpha-Sample:
    Alias: as
    Regex: '[A-Za-z ]+'
    Err-Message: '&cInput must only consist letters of the alphabet!'
  Online-Validator:
    Alias: ov
    Online-Player: true
    Err-Message: '&cThat player is not online!`
```

#### Usage

Once you have input validators defined, you can use them by using the prompt argument `-iv:<validator alias>`. For example:

```
/command <-iv:is integers only!>
/command <-iv:as alphas only!>
/command <-iv:ov online players only!>
```

Since it's a prompt argument, it won't affect other prompt's input validation so you can have something like the following:

```
/command <-iv:is enter only integers> <-iv:as enter only alphas> <-iv:ov online players only!>
```

If it doesn't pass the regex test, the plugin sends the error message and sends the prompt again.

To learn more about regular expressions click [here](https://github.com/Varunram/Awesome-Regex-Resources)


---

# 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://cyr1en.gitbook.io/commandprompter/features/input-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.
