新疆短信内容中手机号码处理,避免含正常手机号的短信发不出去

This commit is contained in:
2026-01-22 18:52:30 +08:00
parent fdd6fce15c
commit a58a007809
@@ -14,14 +14,29 @@ public class XjCommonUtil {
if (StrUtil.isBlank(mobile)) { if (StrUtil.isBlank(mobile)) {
return ""; return "";
} }
// 判空或长度不足3位,直接返回原值
if (mobile.length() < 3) { // 如果长度 <= 4,无需分割
if (mobile.length() <= 4) {
return mobile; return mobile;
} }
return mobile.substring(0, 3) + "_" + mobile.substring(3);
StringBuilder result = new StringBuilder();
int len = mobile.length();
// 从后往前,每4位处理一次
for (int i = len; i > 0; i -= 4) {
int start = Math.max(0, i - 4);
String segment = mobile.substring(start, i);
if (result.length() > 0) {
result.insert(0, "");
}
result.insert(0, segment);
} }
public static void main(String[] args) { return result.toString();
System.out.println(handleMobile("13812345678"));
} }
// public static void main(String[] args) {
// System.out.println(handleMobile("13812345678"));
// }
} }