mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
Validator类添加hasNumber方法✒️
This commit is contained in:
parent
db42db25da
commit
788537d9f0
@ -586,6 +586,17 @@ public class Validator {
|
|||||||
return NumberUtil.isNumber(value);
|
return NumberUtil.isNumber(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否包含数字
|
||||||
|
*
|
||||||
|
* @param value 当前字符串
|
||||||
|
* @return boolean 是否存在数字
|
||||||
|
* @since 5.6.5
|
||||||
|
*/
|
||||||
|
public static boolean hasNumber(CharSequence value) {
|
||||||
|
return ReUtil.contains(PatternPool.NUMBERS, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否为数字
|
* 验证是否为数字
|
||||||
*
|
*
|
||||||
|
@ -20,6 +20,18 @@ public class ValidatorTest {
|
|||||||
Assert.assertTrue(Validator.isNumber("0.33323"));
|
Assert.assertTrue(Validator.isNumber("0.33323"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hasNumberTest() throws Exception {
|
||||||
|
String var1 = "";
|
||||||
|
String var2 = "str";
|
||||||
|
String var3 = "180";
|
||||||
|
String var4 = "身高180体重180";
|
||||||
|
Assert.assertFalse(Validator.hasNumber(var1));
|
||||||
|
Assert.assertFalse(Validator.hasNumber(var2));
|
||||||
|
Assert.assertTrue(Validator.hasNumber(var3));
|
||||||
|
Assert.assertTrue(Validator.hasNumber(var4));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isLetterTest() {
|
public void isLetterTest() {
|
||||||
Assert.assertTrue(Validator.isLetter("asfdsdsfds"));
|
Assert.assertTrue(Validator.isLetter("asfdsdsfds"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user