1、PhoneUtil add 对 hk电话支持,目前大陆和香港的交往变多,需要增加支持

2、天干地支增加注释
3、月份,不光有正月和腊月,农村目前还有 寒月、冬月
This commit is contained in:
duandazhi 2021-04-04 22:33:08 +08:00
parent 7e0c73485b
commit 57be004b4c
4 changed files with 50 additions and 7 deletions

View File

@ -9,7 +9,7 @@ package cn.hutool.core.date.chinese;
public class ChineseMonth {
private static final String[] MONTH_NAME = {"", "", "", "", "", "", "", "", "", "", "十一", "十二"};
private static final String[] MONTH_NAME_TRADITIONAL = {"", "", "", "", "", "", "", "", "", "", "十一", ""};
private static final String[] MONTH_NAME_TRADITIONAL = {"", "", "", "", "", "", "", "", "", "", "", ""};
/**
* 当前农历月份是否为闰月

View File

@ -4,12 +4,18 @@ import java.time.LocalDate;
/**
* 天干地支类
*
* 天干地支简称为干支
* @author looly
* @since 5.4.1
*/
public class GanZhi {
/**
* @see <a href="https://baike.baidu.com/item/%E5%A4%A9%E5%B9%B2%E5%9C%B0%E6%94%AF/278140">天干地支简称干支</a>
* 十天干jiǎbǐngdīnggēngxīnrénguǐ
* 十二地支chǒuyínmǎochénwèishēnyǒuhài
* 十二地支对应十二生肖:------ ------
*/
private static final String[] GAN = new String[]{"", "", "", "", "", "", "", "", "", ""};
private static final String[] ZHI = new String[]{"", "", "", "", "", "", "", "", "", "", "", ""};

View File

@ -49,17 +49,32 @@ public class PatternPool {
public final static Pattern MONEY = Pattern.compile("^(\\d+(?:\\.\\d+)?)$");
/**
* 邮件符合RFC 5322规范正则来自http://emailregex.com/
* 注意email 要宽松一点比如 jetz.chong@hotmail.comjetz-chong@ hotmail.comjetz_chong@hotmail.comdazhi.duan@com.cn 宽松一点把都算是正常的邮箱
*/
// public final static Pattern EMAIL = Pattern.compile("(\\w|.)+@\\w+(\\.\\w+){1,2}");
public final static Pattern EMAIL = Pattern.compile("(?:[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])+)])", Pattern.CASE_INSENSITIVE);
/**
* 移动电话
*/
public final static Pattern MOBILE = Pattern.compile("(?: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 Macau
* 中国台湾 +886 Taiwan
*/
public final static Pattern MOBILE_HK = Pattern.compile("(?:0|852|\\+852)?\\d{8}");
/**
* 座机号码
*/
public final static Pattern TEL = Pattern.compile("0\\d{2,3}-[1-9]\\d{6,7}");
/**
* 座机号码+400+800电话
* @see <a href="https://baike.baidu.com/item/800>800</a>
*/
public final static Pattern TEL_400_800 = Pattern.compile("(?:(?:0\\d{2,3}[\\- ]?[1-9]\\d{6,7})|(?:[48]00[\\- ]?[1-9]\\d{6}))");
/**
* 18位身份证号码
*/

View File

@ -23,6 +23,17 @@ public class PhoneUtil {
return Validator.isMatchRegex(PatternPool.MOBILE, value);
}
/**
* 验证是否为手机号码香港
* @param value 手机号码
* @return 是否为香港手机号码
* @since 5.6.3
* @author dazer & ourslook
*/
public static boolean isMobileHk(CharSequence value) {
return Validator.isMatchRegex(PatternPool.MOBILE_HK, value);
}
/**
* 验证是否为座机号码中国
*
@ -35,14 +46,26 @@ public class PhoneUtil {
}
/**
* 验证是否为座机号码+手机号码中国
* 验证是否为座机号码中国+ 400 + 800
*
* @param value
* @return 是否为座机号码+手机号码中国
* @return 是否为座机号码中国
* @since 5.6.3
* @author dazer & ourslook
*/
public static boolean isTel400800(CharSequence value) {
return Validator.isMatchRegex(PatternPool.TEL_400_800, value);
}
/**
* 验证是否为座机号码+手机号码中国+ 400 + 800电话 + 手机号号码香港
*
* @param value
* @return 是否为座机号码+手机号码中国+手机号码香港
* @since 5.3.11
*/
public static boolean isPhone(CharSequence value) {
return isMobile(value) || isTel(value);
return isMobile(value) || isTel400800(value) || isMobileHk(value);
}
/**
@ -111,5 +134,4 @@ public class PhoneUtil {
public static CharSequence subAfter(CharSequence phone) {
return StrUtil.sub(phone, 7, 11);
}
}