From 6631d57c55a4e2ff57a7cc7371292198bacb75be Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Tue, 17 Mar 2020 22:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=AD=A3=E5=88=99=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/utils/RegexUtil.java | 42 +++++++++++++++++++ .../utils/annotation/AnnotationUtil.java | 22 +++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) 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)) {