Skip to content

Instantly share code, notes, and snippets.

@Limuyang1013
Created January 4, 2016 08:32
Show Gist options
  • Save Limuyang1013/3bb5f94d65607cd68a16 to your computer and use it in GitHub Desktop.
Save Limuyang1013/3bb5f94d65607cd68a16 to your computer and use it in GitHub Desktop.
检测字符串中只能包含:中文、数字、下划线(_)、横线(-)
public static boolean checkNickname(String sequence) {
final String format = "[^\\u4E00-\\u9FA5\\uF900-\\uFA2D\\w-_]";
Pattern pattern = Pattern.compile(format);
Matcher matcher = pattern.matcher(sequence);
return !matcher.find();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment