1
zj
7 hours ago d615fc515fc52d6ed970c11d59a017e48de4be32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.nq.utils;
 
 
 
import org.apache.commons.lang3.StringUtils;
 
 
 
import java.util.regex.Pattern;
 
 
 
public final class PhoneUtil {
 
 
 
    /**
 
     * 严格大陆手机号(11位):有效运营商号段
 
     * 13x | 14[5-9] | 15[0-35-9] | 16[2567] | 17[0-8] | 18x | 19[0-35-9]
 
     */
 
    private static final Pattern STRICT_MOBILE = Pattern.compile(
 
            "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$");
 
 
 
    private PhoneUtil() {
 
    }
 
 
 
    /** 规范为 11 位大陆手机号,非法返回 null */
 
    public static String normalizeChinaMobile(String phone) {
 
        if (StringUtils.isBlank(phone)) {
 
            return null;
 
        }
 
        String digits = phone.trim().replaceAll("[^0-9]", "");
 
        if (digits.startsWith("86") && digits.length() == 13) {
 
            digits = digits.substring(2);
 
        }
 
        if (digits.length() != 11 || !digits.startsWith("1")) {
 
            return null;
 
        }
 
        return digits;
 
    }
 
 
 
    public static boolean isValidChinaMobile(String phone) {
 
        String normalized = normalizeChinaMobile(phone);
 
        return normalized != null && STRICT_MOBILE.matcher(normalized).matches();
 
    }
 
}