mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix(IdCardUtil): Fix isValidTWCard string index out of range
This commit is contained in:
parent
0e15b89cfa
commit
09355e6cc5
@ -343,7 +343,7 @@ public class IdcardUtil {
|
||||
* @return 验证码是否符合
|
||||
*/
|
||||
public static boolean isValidTWCard(String idcard) {
|
||||
if (StrUtil.isEmpty(idcard)) {
|
||||
if (StrUtil.isEmpty(idcard) || idcard.length() != 10) {
|
||||
return false;
|
||||
}
|
||||
String start = idcard.substring(0, 1);
|
||||
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 身份证单元测试
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
@ -111,4 +111,17 @@ public class IdcardUtilTest {
|
||||
boolean flag=IdcardUtil.isValidHKCard(hkCard);
|
||||
Assert.assertTrue(flag);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValidTWCardIdTest() {
|
||||
String twCard = "B221690311";
|
||||
boolean flag = IdcardUtil.isValidTWCard(twCard);
|
||||
Assert.assertTrue(flag);
|
||||
String errTwCard1 = "M517086311";
|
||||
flag = IdcardUtil.isValidTWCard(errTwCard1);
|
||||
Assert.assertFalse(flag);
|
||||
String errTwCard2 = "B2216903112";
|
||||
flag = IdcardUtil.isValidTWCard(errTwCard2);
|
||||
Assert.assertFalse(flag);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user