Add a validator for the input string format.
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
package space.kklochko.jdbc_hospital_example.cli.validators;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class InputStringFormatValidator extends Validator {
|
||||
String command;
|
||||
String formatRegEx = "\\w+\\s\\w+\\((|[^)]+)\\)";
|
||||
|
||||
public InputStringFormatValidator(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
Pattern pattern = Pattern.compile(formatRegEx);
|
||||
return pattern.matcher(command).matches();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return "Please, check the format: `command item(arg1=value1, ...)`. Or check the `help`";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user