private boolean isValidName(String text) { boolean result = true; String test = text; Pattern pattern; try { pattern = Pattern.compile(Config.CNAME_TEMPLATE); } catch (PatternSyntaxException e) // case of illegal pattern { pattern = Pattern.compile(".*"); } Matcher regexp = pattern.matcher(test); if (!regexp.matches()) { result = false; } return result; }