diff --git a/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java b/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java index 5f201b6..a215211 100644 --- a/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java +++ b/cloud-common/src/main/java/com/cm/common/utils/RegexUtil.java @@ -47,6 +47,18 @@ public class RegexUtil { * 身份证 */ private static final Pattern PATTERN_IDENTITY = Pattern.compile("(^\\d{15}$)|(^\\d{17}(x|X|\\d)$)"); + /** + * 字母 + */ + private static final Pattern PATTERN_LETTER = Pattern.compile("[a-zA-Z]+"); + /** + * 中文 + */ + private static final Pattern PATTERN_CHINESE = Pattern.compile("[\\u4e00-\\u9fa5]+"); + /** + * 数字 + */ + private static final Pattern PATTERN_NUMBER = Pattern.compile("\\d+"); /** * 弱密码 */ @@ -140,6 +152,36 @@ public class RegexUtil { return PATTERN_IDENTITY.matcher(input).matches(); } + /** + * 判断是字母 + * + * @param input + * @return + */ + public static boolean isLetter(String input) { + return PATTERN_LETTER.matcher(input).matches(); + } + + /** + * 判断是中文 + * + * @param input + * @return + */ + public static boolean isChinese(String input) { + return PATTERN_CHINESE.matcher(input).matches(); + } + + /** + * 判断是数字 + * + * @param input + * @return + */ + public static boolean isNumber(String input) { + return PATTERN_NUMBER.matcher(input).matches(); + } + /** * 自定义判断 * diff --git a/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java b/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java index 4b796a6..daa025d 100644 --- a/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java +++ b/cloud-common/src/main/java/com/cm/common/utils/annotation/AnnotationUtil.java @@ -138,32 +138,42 @@ public class AnnotationUtil { } if (StringUtils.equals("phone", verifyType)) { if (!RegexUtil.isPhone(value)) { - throw new ParamsException(String.format("%s格式不手机格式", name)); + throw new ParamsException(String.format("%s格式非手机格式", name)); } return; } else if (StringUtils.equals("email", verifyType)) { if (!RegexUtil.isEmail(value)) { - throw new ParamsException(String.format("%s格式不邮件格式", name)); + throw new ParamsException(String.format("%s格式非邮件格式", name)); } return; } else if (StringUtils.equals("url", verifyType)) { if (!RegexUtil.isUrl(value)) { - throw new ParamsException(String.format("%s格式不url格式", name)); + throw new ParamsException(String.format("%s格式非url格式", name)); } return; } else if (StringUtils.equals("number", verifyType)) { if (!NumberUtils.isNumber(value)) { - throw new ParamsException(String.format("%s格式不数字格式", name)); + throw new ParamsException(String.format("%s格式非数字格式", name)); } return; } else if (StringUtils.equals("date", verifyType)) { if (!RegexUtil.isDate(value)) { - throw new ParamsException(String.format("%s格式不日期格式", name)); + throw new ParamsException(String.format("%s格式非日期格式", name)); } return; } else if (StringUtils.equals("identity", verifyType)) { if (!RegexUtil.isIdentity(value)) { - throw new ParamsException(String.format("%s格式不身份证格式", name)); + throw new ParamsException(String.format("%s格式非身份证格式", name)); + } + return; + } else if (StringUtils.equals("letter", verifyType)) { + if (!RegexUtil.isLetter(value)) { + throw new ParamsException(String.format("%s格式非字母格式", name)); + } + return; + } else if (StringUtils.equals("chinese", verifyType)) { + if (!RegexUtil.isLetter(value)) { + throw new ParamsException(String.format("%s格式非中文格式", name)); } return; } else if (StringUtils.equals("custom", verifyType)) {