001    package org.bukkit.conversations;
002    
003    import java.util.regex.Pattern;
004    
005    /**
006     * RegexPrompt is the base class for any prompt that requires an input
007     * validated by a regular expression.
008     */
009    public abstract class RegexPrompt extends ValidatingPrompt {
010    
011        private Pattern pattern;
012    
013        public RegexPrompt(String regex) {
014            this(Pattern.compile(regex));
015        }
016    
017        public RegexPrompt(Pattern pattern) {
018            super();
019            this.pattern = pattern;
020        }
021    
022        private RegexPrompt() {}
023    
024        @Override
025        protected boolean isInputValid(ConversationContext context, String input) {
026            return pattern.matcher(input).matches();
027        }
028    }