转: http://www.maxiaoguo.com/foods/362.html
1、要求4-10个中英文 数字或者 下划线
/**
* 验证昵称* @param code
* @return
*/public static boolean regiestNickCode(String code){
String regiex = "[\u4e00-\u9fa50-9a-zA-Z_]{4,10}";
Pattern pattern = Pattern.compile(regiex);
Matcher matcher = pattern.matcher(code);
boolean b= matcher.matches();
return b;
}
2、要求 支持6-20个 数字 字母 下划线 减号 需要以字母开头
/*** 验证昵称
* @param code
* @return
*/
public static boolean regiestUserName(String code){
String regiex = "[a-zA-Z]{1}[a-zA-Z0-9_-]{5,20}";
Pattern pattern = Pattern.compile(regiex);
Matcher matcher = pattern.matcher(code);
boolean b= matcher.matches();
return b;
}