mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
!592 Validator 增加:中国人姓名正则校验
Merge pull request !592 from dazer007/v5-dev
This commit is contained in:
commit
c60f6a6547
@ -163,6 +163,11 @@ public class PatternPool {
|
|||||||
* 仅限:中国驾驶证档案编号
|
* 仅限:中国驾驶证档案编号
|
||||||
*/
|
*/
|
||||||
public static final Pattern CAR_DRIVING_LICENCE = Pattern.compile(RegexPool.CAR_DRIVING_LICENCE);
|
public static final Pattern CAR_DRIVING_LICENCE = Pattern.compile(RegexPool.CAR_DRIVING_LICENCE);
|
||||||
|
/**
|
||||||
|
* 中国人姓名
|
||||||
|
* 总结中国人姓名:2-60位,只能是中文和新疆人的点.
|
||||||
|
*/
|
||||||
|
public static final Pattern CHINESE_NAME = Pattern.compile(RegexPool.CHINESE_NAME);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -176,4 +176,27 @@ public interface RegexPool {
|
|||||||
* 仅限:中国驾驶证档案编号
|
* 仅限:中国驾驶证档案编号
|
||||||
*/
|
*/
|
||||||
String CAR_DRIVING_LICENCE = "^[0-9]{12}$";
|
String CAR_DRIVING_LICENCE = "^[0-9]{12}$";
|
||||||
|
/**
|
||||||
|
* 中国人姓名
|
||||||
|
* @see PatternPool#CHINESES [\u4E00-\u9FFF]+ 中文字
|
||||||
|
* @see PatternPool#GENERAL_WITH_CHINESE "^[\u4E00-\u9FFF\w·]{2,60}$" 中文字、英文字母、数字和下划线
|
||||||
|
* 新疆人名里面的点是 · 输入法中文状态下,键盘左上角数字1前面的那个符号;错误字符:..。..
|
||||||
|
* 正确新疆人:
|
||||||
|
* 霍加阿卜杜拉·麦提喀斯木
|
||||||
|
* 玛合萨提别克·哈斯木别克
|
||||||
|
* 阿布都热依木江·艾斯卡尔
|
||||||
|
* 阿卜杜尼亚孜·毛力尼亚孜
|
||||||
|
* ----------
|
||||||
|
* 错误示例:孟 伟 reason: 有空格
|
||||||
|
* 错误示例:连逍遥0 reason: 数字
|
||||||
|
* 错误示例:依帕古丽-艾则孜 reason: 特殊符号
|
||||||
|
* 错误示例:牙力空.买提萨力 reason: 新疆人的点不对
|
||||||
|
* 错误示例:王建鹏2002-3-2 reason: 有数字、特殊符号
|
||||||
|
* 错误示例:雷金默(雷皓添) reason: 有括号
|
||||||
|
* 错误示例:翟冬:亮 reason: 有特殊符号
|
||||||
|
* 错误示例:李 reason: 少于2位
|
||||||
|
* ----------
|
||||||
|
* 总结中国人姓名:2-60位,只能是中文和新疆人的点·
|
||||||
|
*/
|
||||||
|
String CHINESE_NAME = "^[\u4E00-\u9FFF·]{2,60}$";
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,11 @@ public class Validator {
|
|||||||
* 驾驶证 别名:驾驶证档案编号、行驶证编号;12位数字字符串;仅限:中国驾驶证档案编号
|
* 驾驶证 别名:驾驶证档案编号、行驶证编号;12位数字字符串;仅限:中国驾驶证档案编号
|
||||||
*/
|
*/
|
||||||
public final static Pattern CAR_DRIVING_LICENCE = PatternPool.CAR_DRIVING_LICENCE;
|
public final static Pattern CAR_DRIVING_LICENCE = PatternPool.CAR_DRIVING_LICENCE;
|
||||||
|
/**
|
||||||
|
* 中国人姓名
|
||||||
|
* 总结中国人姓名:2-60位,只能是中文和新疆人的点.
|
||||||
|
*/
|
||||||
|
public static final Pattern CHINESE_NAME = PatternPool.CHINESE_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 给定值是否为{@code true}
|
* 给定值是否为{@code true}
|
||||||
@ -1186,6 +1191,21 @@ public class Validator {
|
|||||||
return isMatchRegex(CAR_DRIVING_LICENCE, value);
|
return isMatchRegex(CAR_DRIVING_LICENCE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是中国人姓名
|
||||||
|
*
|
||||||
|
* @author dazer
|
||||||
|
*
|
||||||
|
* @param value 中国人姓名
|
||||||
|
* @return 是否是正确的中国人姓名
|
||||||
|
* @see 5.8.0.M3
|
||||||
|
*/
|
||||||
|
public static boolean isChineseName(CharSequence value) {
|
||||||
|
return isMatchRegex(CHINESE_NAME, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证是否为驾驶证 别名:驾驶证档案编号、行驶证编号
|
* 验证是否为驾驶证 别名:驾驶证档案编号、行驶证编号
|
||||||
*
|
*
|
||||||
|
@ -245,4 +245,15 @@ public class ValidatorTest {
|
|||||||
Assert.assertTrue(Validator.isMatchRegex(Validator.URL, content));
|
Assert.assertTrue(Validator.isMatchRegex(Validator.URL, content));
|
||||||
Assert.assertTrue(Validator.isMatchRegex(Validator.URL_HTTP, content));
|
Assert.assertTrue(Validator.isMatchRegex(Validator.URL_HTTP, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChineseNameTest(){
|
||||||
|
Assert.assertTrue(Validator.isChineseName("阿卜杜尼亚孜·毛力尼亚孜"));
|
||||||
|
Assert.assertFalse(Validator.isChineseName("阿卜杜尼亚孜./毛力尼亚孜"));
|
||||||
|
Assert.assertTrue(Validator.isChineseName("段正淳"));
|
||||||
|
Assert.assertFalse(Validator.isChineseName("孟 伟"));
|
||||||
|
Assert.assertFalse(Validator.isChineseName("李"));
|
||||||
|
Assert.assertFalse(Validator.isChineseName("连逍遥0"));
|
||||||
|
Assert.assertFalse(Validator.isChineseName("SHE"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user