Class PhoneNumberUtil
java.lang.Object
cloud.opencode.base.sms.util.PhoneNumberUtil
Phone Number Utility
手机号码工具类
Utilities for phone number validation and formatting.
手机号码验证和格式化工具。
Features | 主要功能:
- Phone number validation (China, international) - 手机号验证(中国、国际)
- Phone number normalization - 手机号标准化
- Country code mapping - 国家代码映射
- Phone number masking - 手机号脱敏
Usage Examples | 使用示例:
boolean valid = PhoneNumberUtil.isValid("+8613800138000");
String normalized = PhoneNumberUtil.normalize("138-0013-8000");
String masked = PhoneNumberUtil.mask("13800138000"); // "138****8000"
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(1) - phone numbers have bounded length (max ~15 digits) - 时间复杂度: O(1),手机号长度有限(最多约 15 位)
- Space complexity: O(1) - pre-compiled regex patterns - 空间复杂度: O(1) 预编译正则表达式
- Since:
- JDK 25, opencode-base-sms V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringextractCountryCode(String phoneNumber) Extract country code from phone number 从手机号码提取国家代码static StringformatChina(String phoneNumber) Format China mobile number 格式化中国手机号码static StringformatWithCountryCode(String phoneNumber, String countryCode) Format with country code 使用国家代码格式化static StringgetCountryDialingCode(String countryCode) Get country code 获取国家代码static booleanisChinaMobile(String phoneNumber) Validate China mobile number 验证中国手机号码static booleanValidate phone number 验证手机号码static StringMask phone number for display 掩码手机号码用于显示static StringNormalize phone number 标准化手机号码
-
Method Details
-
isValid
Validate phone number 验证手机号码- Parameters:
phoneNumber- the phone number | 手机号码- Returns:
- true if valid | 如果有效返回true
-
isChinaMobile
Validate China mobile number 验证中国手机号码- Parameters:
phoneNumber- the phone number | 手机号码- Returns:
- true if valid | 如果有效返回true
-
normalize
-
formatWithCountryCode
-
formatChina
-
mask
-
getCountryDialingCode
-
extractCountryCode
-