hutool.core.util.phone¶
Module Contents¶
Classes¶
手机号工具类 |
API¶
- class hutool.core.util.phone.PhoneUtil¶
手机号工具类
- _MOBILE_PATTERN = 'compile(...)'¶
- _MOBILE_HK_PATTERN = 'compile(...)'¶
- _MOBILE_TW_PATTERN = 'compile(...)'¶
- _MOBILE_MO_PATTERN = 'compile(...)'¶
- _FIXED_PHONE_PATTERN = 'compile(...)'¶
- _TEL_400_800_PATTERN = 'compile(...)'¶
- static is_mobile(phone: str) bool¶
是否为中国大陆手机号
- 参数:
phone – 手机号字符串
- 返回:
是否合法
- static is_mobile_hk(phone: str) bool¶
是否为香港手机号(8位,5/6/9开头)
- 参数:
phone – 手机号字符串
- 返回:
是否合法
- static is_mobile_tw(phone: str) bool¶
是否为台湾手机号(09开头10位)
- 参数:
phone – 手机号字符串
- 返回:
是否合法
- static is_mobile_mo(phone: str) bool¶
是否为澳门手机号(6开头8位)
- 参数:
phone – 手机号字符串
- 返回:
是否合法
- static is_phone(phone: str) bool¶
是否为电话号码(手机或座机)
- 参数:
phone – 电话号码字符串
- 返回:
是否合法
- static is_mobile_simple(phone: str) bool¶
简单判断是否为手机号(11位数字,1开头)
相比
is_mobile()规则更宽松,仅检查长度和首位。- 参数:
phone – 手机号字符串
- 返回:
是否可能是手机号
- static hide_before(phone: str) str¶
隐藏前3位,如 138****1234
- 参数:
phone – 手机号字符串
- 返回:
脱敏后的手机号
- static hide_between(phone: str) str¶
隐藏中间4位,如 138****1234
- 参数:
phone – 手机号字符串
- 返回:
脱敏后的手机号
- static hide_after(phone: str) str¶
隐藏后4位
- 参数:
phone – 手机号字符串
- 返回:
脱敏后的手机号
- static sub_before(phone: str) str¶
获取手机号前3位
- 参数:
phone – 手机号字符串
- 返回:
前3位
- static sub_after(phone: str) str¶
获取手机号后4位
- 参数:
phone – 手机号字符串
- 返回:
后4位
- static is_tel(tel: str) bool¶
是否为座机号码(含区号)。
- 参数:
tel – 座机号码
- 返回:
是否合法
- static is_tel_400_800(tel: str) bool¶
是否为 400 或 800 号码。
- 参数:
tel – 电话号码
- 返回:
是否合法
- static sub_between(phone: str, begin: int, end: int) str¶
截取手机号指定位之间的内容。
- 参数:
phone – 手机号
begin – 起始索引(包含)
end – 结束索引(不包含)
- 返回:
截取的子串
- static sub_tel_before(tel: str) str¶
获取座机号码的区号部分。
- 参数:
tel – 座机号码
- 返回:
区号
- static sub_tel_after(tel: str) str¶
获取座机号码的号码部分(去掉区号)。
- 参数:
tel – 座机号码
- 返回:
号码部分