fix Validator

This commit is contained in:
Looly 2020-05-30 08:07:02 +08:00
parent e7bc77aff5
commit b8f8a3277f
3 changed files with 36 additions and 15 deletions

View File

@ -29,6 +29,8 @@
* 【core 】 DateUtil增加dayOfYear方法pr#895@Github
* 【core 】 DateUtil增加dayOfYear方法pr#895@Github
* 【http 】 HttpUtil增加downloadBytes方法pr#895@Github
* 【core 】 isMactchRegex失效标记增加isMatchRegexissue#I1IPJG@Gitee
* 【core 】 优化Validator.isChinese
### Bug修复
* 【core 】 修复SimpleCache死锁问题issue#I1HOKB@Gitee

View File

@ -327,17 +327,6 @@ public class Validator {
validateNotEqual(t1, t2, errorMsg);
}
/**
* 通过正则表达式验证
*
* @param regex 正则
* @param value
* @return 是否匹配正则
*/
public static boolean isMactchRegex(String regex, CharSequence value) {
return ReUtil.isMatch(regex, value);
}
/**
* 通过正则表达式验证<br>
* 不符合正则抛出{@link ValidateException} 异常
@ -350,7 +339,7 @@ public class Validator {
* @throws ValidateException 验证异常
*/
public static <T extends CharSequence> T validateMatchRegex(String regex, T value, String errorMsg) throws ValidateException {
if (false == isMactchRegex(regex, value)) {
if (false == isMatchRegex(regex, value)) {
throw new ValidateException(errorMsg);
}
return value;
@ -369,6 +358,19 @@ public class Validator {
return ReUtil.isMatch(pattern, value);
}
/**
* 通过正则表达式验证
*
* @param regex 正则
* @param value
* @return 是否匹配正则
* @deprecated 拼写错误请使用{@link #isMatchRegex(String, CharSequence)}
*/
@Deprecated
public static boolean isMactchRegex(String regex, CharSequence value) {
return ReUtil.isMatch(regex, value);
}
/**
* 通过正则表达式验证
*
@ -380,6 +382,17 @@ public class Validator {
return ReUtil.isMatch(pattern, value);
}
/**
* 通过正则表达式验证
*
* @param regex 正则
* @param value
* @return 是否匹配正则
*/
public static boolean isMatchRegex(String regex, CharSequence value) {
return ReUtil.isMatch(regex, value);
}
/**
* 验证是否为英文字母 数字和下划线
*
@ -422,7 +435,7 @@ public class Validator {
if (max <= 0) {
reg = "^\\w{" + min + ",}$";
}
return isMactchRegex(reg, value);
return isMatchRegex(reg, value);
}
/**
@ -954,13 +967,13 @@ public class Validator {
}
/**
* 验证是否为汉字
* 验证是否为汉字
*
* @param value
* @return 是否为汉字
*/
public static boolean isChinese(CharSequence value) {
return isMactchRegex("^" + ReUtil.RE_CHINESES + "$", value);
return isMatchRegex(PatternPool.CHINESES, value);
}
/**

View File

@ -136,4 +136,10 @@ public class ValidatorTest {
Assert.assertTrue(Validator.isPlateNumber("粤BA03205"));
Assert.assertTrue(Validator.isPlateNumber("闽20401领"));
}
@Test
public void isChineseTest(){
Assert.assertTrue(Validator.isChinese("全都是中文"));
Assert.assertFalse(Validator.isChinese("not全都是中文"));
}
}