This commit is contained in:
Looly 2022-09-24 01:08:24 +08:00
parent 9dfac34f69
commit 186289c979
2 changed files with 17 additions and 20 deletions

View File

@ -54,16 +54,13 @@ public interface RegexPool {
String EMAIL = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])";
/**
* 移动电话
* eg: 中国大陆 +86 180 4953 13992位区域码标示+11位数字
* 中国大陆 +86 Mainland China
*/
String MOBILE = "(?:0|86|\\+86)?1[3-9]\\d{9}";
/**
* 中国香港移动电话
* eg: 中国香港 +852 5100 4810 三位区域码+10位数字, 中国香港手机号码8位数
* eg: 中国大陆 +86 180 4953 13992位区域码标示+13位数字
* 中国大陆 +86 Mainland China
* 中国香港 +852 Hong Kong
* 中国澳门 +853 Macao
* 中国台湾 +886 Taiwan
*/
String MOBILE_HK = "(?:0|852|\\+852)?\\d{8}";
/**
@ -74,7 +71,7 @@ public interface RegexPool {
String MOBILE_TW = "(?:0|886|\\+886)?(?:|-)09\\d{8}";
/**
* 中国澳门移动电话
* eg: 中国台湾 +853 68 00000 三位区域码 +号码以数字6开头 + 7位数字, 中国台湾手机号码8位数
* eg: 中国澳门 +853 68 00000 三位区域码 +号码以数字6开头 + 7位数字, 中国澳门手机号码8位数
* 中国澳门 +853 Macao 国际域名缩写MO
*/
String MOBILE_MO = "(?:0|853|\\+853)?(?:|-)6\\d{7}";

View File

@ -14,10 +14,10 @@ public class PhoneUtilTest {
@Test
public void testCheck() {
String mobile = "13612345678";
String tel = "010-88993108";
String errMobile = "136123456781";
String errTel = "010-889931081";
final String mobile = "13612345678";
final String tel = "010-88993108";
final String errMobile = "136123456781";
final String errTel = "010-889931081";
Assert.assertTrue(PhoneUtil.isMobile(mobile));
Assert.assertTrue(PhoneUtil.isTel(tel));
@ -32,26 +32,26 @@ public class PhoneUtilTest {
@Test
public void testTel() {
ArrayList<String> tels = new ArrayList<>();
final ArrayList<String> tels = new ArrayList<>();
tels.add("010-12345678");
tels.add("020-9999999");
tels.add("0755-7654321");
ArrayList<String> errTels = new ArrayList<>();
final ArrayList<String> errTels = new ArrayList<>();
errTels.add("010 12345678");
errTels.add("A20-9999999");
errTels.add("0755-7654.321");
errTels.add("13619887123");
for (String s : tels) {
for (final String s : tels) {
Assert.assertTrue(PhoneUtil.isTel(s));
}
for (String s : errTels) {
for (final String s : errTels) {
Assert.assertFalse(PhoneUtil.isTel(s));
}
}
@Test
public void testHide() {
String mobile = "13612345678";
final String mobile = "13612345678";
Assert.assertEquals("*******5678", PhoneUtil.hideBefore(mobile));
Assert.assertEquals("136****5678", PhoneUtil.hideBetween(mobile));
@ -60,7 +60,7 @@ public class PhoneUtilTest {
@Test
public void testSubString() {
String mobile = "13612345678";
final String mobile = "13612345678";
Assert.assertEquals("136", PhoneUtil.subBefore(mobile));
Assert.assertEquals("1234", PhoneUtil.subBetween(mobile));
Assert.assertEquals("5678", PhoneUtil.subAfter(mobile));
@ -68,22 +68,22 @@ public class PhoneUtilTest {
@Test
public void testNewTel() {
ArrayList<String> tels = new ArrayList<>();
final ArrayList<String> tels = new ArrayList<>();
tels.add("010-12345678");
tels.add("01012345678");
tels.add("020-9999999");
tels.add("0209999999");
tels.add("0755-7654321");
tels.add("07557654321");
ArrayList<String> errTels = new ArrayList<>();
final ArrayList<String> errTels = new ArrayList<>();
errTels.add("010 12345678");
errTels.add("A20-9999999");
errTels.add("0755-7654.321");
errTels.add("13619887123");
for (String s : tels) {
for (final String s : tels) {
Assert.assertTrue(PhoneUtil.isTel(s));
}
for (String s : errTels) {
for (final String s : errTels) {
Assert.assertFalse(PhoneUtil.isTel(s));
}
Assert.assertEquals("010", PhoneUtil.subTelBefore("010-12345678"));