派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
package com.qxueyou.scc.base.util;
 
import java.util.regex.Pattern;
 
/**
 * 手机号码工具类
 * @author 德虎
 *
 */
public final class PhoneNOUtils {
 
    private final static Pattern pattern = Pattern.compile("1[3,4,5,7,8]\\d{9}");
    
    /**
     * 验证是否为有效手机号
     * @param phoneNo
     * @return
     */
    public static boolean isValidPhoneNo(String phoneNo){
        
        return pattern.matcher(phoneNo).matches();
        
    }
    
    /**
     * 替换手机号关键号码为*
     * @param phoneNo
     * @return
     */
    public static String coverKeyNo(String phoneNo){
        
        if(phoneNo.length()!=11){
            return phoneNo;
        }
        
        return phoneNo.substring(0, 3).concat("****").concat(phoneNo.substring(7));
        
    }
    
    public static void main(String[] args){
        System.out.println(PhoneNOUtils.coverKeyNo("18676726706"));
    }
}