Add a validator for the input string format.

This commit is contained in:
2023-10-29 12:37:58 +02:00
parent 5159beee68
commit fb9ee07cbe
2 changed files with 47 additions and 0 deletions
@@ -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`";
}
}