public void register(RegisterBody registerBody) {
HttpServletRequest request = ServletUtils.getRequest();
String username = registerBody.getUsername();
if (StringUtils.isEmpty(username)) {
throw new UserException("sms context is empty!");
}
Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]");
Matcher m = p.matcher(username);
if (m.find()) {
throw new UserException("内容包含中文或中文字符!");
}
java判断字符串是否是汉字
-
字符串是否包含中文
-
* @param str 待校验字符串
-
* @return true 包含中文字符 false 不包含中文字符
-