mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix Validator
This commit is contained in:
parent
e7bc77aff5
commit
b8f8a3277f
@ -29,6 +29,8 @@
|
|||||||
* 【core 】 DateUtil增加dayOfYear方法(pr#895@Github)
|
* 【core 】 DateUtil增加dayOfYear方法(pr#895@Github)
|
||||||
* 【core 】 DateUtil增加dayOfYear方法(pr#895@Github)
|
* 【core 】 DateUtil增加dayOfYear方法(pr#895@Github)
|
||||||
* 【http 】 HttpUtil增加downloadBytes方法(pr#895@Github)
|
* 【http 】 HttpUtil增加downloadBytes方法(pr#895@Github)
|
||||||
|
* 【core 】 isMactchRegex失效标记,增加isMatchRegex(issue#I1IPJG@Gitee)
|
||||||
|
* 【core 】 优化Validator.isChinese
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee)
|
* 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee)
|
||||||
|
@ -327,17 +327,6 @@ public class Validator {
|
|||||||
validateNotEqual(t1, t2, errorMsg);
|
validateNotEqual(t1, t2, errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过正则表达式验证
|
|
||||||
*
|
|
||||||
* @param regex 正则
|
|
||||||
* @param value 值
|
|
||||||
* @return 是否匹配正则
|
|
||||||
*/
|
|
||||||
public static boolean isMactchRegex(String regex, CharSequence value) {
|
|
||||||
return ReUtil.isMatch(regex, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过正则表达式验证<br>
|
* 通过正则表达式验证<br>
|
||||||
* 不符合正则抛出{@link ValidateException} 异常
|
* 不符合正则抛出{@link ValidateException} 异常
|
||||||
@ -350,7 +339,7 @@ public class Validator {
|
|||||||
* @throws ValidateException 验证异常
|
* @throws ValidateException 验证异常
|
||||||
*/
|
*/
|
||||||
public static <T extends CharSequence> T validateMatchRegex(String regex, T value, String errorMsg) 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);
|
throw new ValidateException(errorMsg);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@ -369,6 +358,19 @@ public class Validator {
|
|||||||
return ReUtil.isMatch(pattern, value);
|
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);
|
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) {
|
if (max <= 0) {
|
||||||
reg = "^\\w{" + min + ",}$";
|
reg = "^\\w{" + min + ",}$";
|
||||||
}
|
}
|
||||||
return isMactchRegex(reg, value);
|
return isMatchRegex(reg, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -954,13 +967,13 @@ public class Validator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否为汉字
|
* 验证是否都为汉字
|
||||||
*
|
*
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 是否为汉字
|
* @return 是否为汉字
|
||||||
*/
|
*/
|
||||||
public static boolean isChinese(CharSequence value) {
|
public static boolean isChinese(CharSequence value) {
|
||||||
return isMactchRegex("^" + ReUtil.RE_CHINESES + "$", value);
|
return isMatchRegex(PatternPool.CHINESES, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,4 +136,10 @@ public class ValidatorTest {
|
|||||||
Assert.assertTrue(Validator.isPlateNumber("粤BA03205"));
|
Assert.assertTrue(Validator.isPlateNumber("粤BA03205"));
|
||||||
Assert.assertTrue(Validator.isPlateNumber("闽20401领"));
|
Assert.assertTrue(Validator.isPlateNumber("闽20401领"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChineseTest(){
|
||||||
|
Assert.assertTrue(Validator.isChinese("全都是中文"));
|
||||||
|
Assert.assertFalse(Validator.isChinese("not全都是中文"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user