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. 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

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

Last updated