-
-
Notifications
You must be signed in to change notification settings - Fork 8
Input Validation
Available on versions 2.4.0+ of CommandPrompter
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
An input validator could have any key. But under that key, there must be an Alias
and Regex
key. There's also an optional key that you can set called Err-Message
. The following is an example of an input validators that's included with CommandPrompter by default.
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!'
Once you have input validators defined, you can use them by using the the prompt argument -iv:<validator alias>
.
For example:
/command <-iv:is integers only!>
/command <-iv:as alphas 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>
If it doesn't pass the regex test, the plugin sends the err message and sends the prompt again.
To learn more about regular expressions go click here
Show the wonderful people at Lithium Hosting some love ❤️