mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复IdcardUtil.isValidHKCard校验问题
This commit is contained in:
parent
9ce821650f
commit
0de4581927
@ -21,6 +21,7 @@
|
|||||||
* 【core 】 修复BeanUtil.copyProperties中mapToMap时key被转为String问题(issue#3645@Github)
|
* 【core 】 修复BeanUtil.copyProperties中mapToMap时key被转为String问题(issue#3645@Github)
|
||||||
* 【core 】 修复FileUtil.file末尾换行符导致路径判断错误的问题(issue#IAB65V@Gitee)
|
* 【core 】 修复FileUtil.file末尾换行符导致路径判断错误的问题(issue#IAB65V@Gitee)
|
||||||
* 【core 】 修复FileTypeUtil.getType空指针问题(issue#IAD5JM@Gitee)
|
* 【core 】 修复FileTypeUtil.getType空指针问题(issue#IAD5JM@Gitee)
|
||||||
|
* 【core 】 修复IdcardUtil.isValidHKCard校验问题(issue#IAFOLI@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.29(2024-07-03)
|
# 5.8.29(2024-07-03)
|
||||||
|
@ -413,6 +413,10 @@ public class IdcardUtil {
|
|||||||
* @return 验证码是否符合
|
* @return 验证码是否符合
|
||||||
*/
|
*/
|
||||||
public static boolean isValidHKCard(String idcard) {
|
public static boolean isValidHKCard(String idcard) {
|
||||||
|
if(false == idcard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?$")){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String card = idcard.replaceAll("[()]", "");
|
String card = idcard.replaceAll("[()]", "");
|
||||||
int sum;
|
int sum;
|
||||||
if (card.length() == 9) {
|
if (card.length() == 9) {
|
||||||
|
@ -178,4 +178,12 @@ public class IdcardUtilTest {
|
|||||||
public void issueI88YKMTest() {
|
public void issueI88YKMTest() {
|
||||||
Assert.assertTrue(IdcardUtil.isValidCard("111111111111111"));
|
Assert.assertTrue(IdcardUtil.isValidCard("111111111111111"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issueIAFOLITest() {
|
||||||
|
String idcard = "H01487002";
|
||||||
|
Assert.assertFalse(IdcardUtil.isValidHKCard(idcard));
|
||||||
|
Assert.assertNull(IdcardUtil.isValidCard10(idcard));
|
||||||
|
Assert.assertFalse(IdcardUtil.isValidCard(idcard));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user