Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2013 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/51da760720034abcc837 to your computer and use it in GitHub Desktop.
Save anonymous/51da760720034abcc837 to your computer and use it in GitHub Desktop.
private boolean isValid(String tag) {
int alphaCount = 0;
for (int i = 0; i < tag.length(); i++) {
final char c = tag.charAt(i);
if (c == '-') {
if (alphaCount == 0) {
return false;
}
} else if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9')) {
alphaCount++;
if (alphaCount > 8) {
return false;
}
} else {
return false;
}
}
return (alphaCount != 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment