class StackNameFormatValidator implements ConstraintValidator<ValidStackNameFormat, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        Pattern pattern = Pattern.compile("(^[a-z][-a-z0-9]*[a-z0-9]$)");
        Matcher matcher = pattern.matcher(value);
        return matcher.matches();
    }

}