Skip to content

Instantly share code, notes, and snippets.

Created July 6, 2014 07:32
Show Gist options
  • Save anonymous/0f09a7b95c286b2469cc to your computer and use it in GitHub Desktop.
Save anonymous/0f09a7b95c286b2469cc to your computer and use it in GitHub Desktop.
Validate username with regular expression
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Give true is all condition matches, otherwise false.
* @param String
* @return boolean
*/
private boolean validateUserName(String username){
Pattern pattern = Pattern.compile("^[a-z0-9_-]{3,15}$");
Matcher matcher = pattern.matcher(username);
return matcher.matches();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment