/**
-
校验用户名判断:头部尾部不能使空格,不能是中文,不能使全角,不能有星号,长度6-16 其实 中文 和 全角 的 new
-
String(charStr.getBytes(“UTF-8”),“8859_1”).getBytes().length=6
-
字母、数字、特殊符号new
-
String(charStr.getBytes(“UTF-8”),“8859_1”).getBytes().length=1
*/
public static boolean validateUserName(String username) {
/**
- 长度6-16
*/
if (!((username.length() >= 6) && (username.length() <= 16))) {
return false;
}
/**
- 头部不能有空格
*/
if (username.substring(0, 1).equals(" ")) {// 头部有空格
System.out.println(33);
return false;
}
/**
- 未部不能有空格
*/
if (username.endsWith(" ")) {// 未部有空格
return false;
}
if (username.contains(" ")) {// 不能含有
return false;
}
/**
- 不能有中文
*/
Pattern pattern1 = Pattern.compile(“[^\u4E00-\u9FA5]*”); // 不是中文
Matcher m1 = pattern1.matcher(username);
if (!m1.matches()) {
return false;
}
/**
- 不能有*号
*/
pattern1 = Pattern.compile(“[^\]”); // 不是*号
<