java 判断手机号运营商

发布于:2020-08-08 17:35:50

/**
 * @Author guocongcong
 * @Date 2018/2/28
 * @Describe 手机号工具类
 */
 
public class PhoneUtils {
 
    /*
        1、移动号段有134,135,136,137, 138,139,147,150,151, 152,157,158,159,178,182,183,184,187,188。
        2、联通号段有130,131,132,155,156,185,186,145,176。
        3、电信号段有133,153,177.173,180,181,189。
        */
    public static final String YD_STRING = "^[1]{1}(([3]{1}[4-9]{1})|([5]{1}[012789]{1})|([8]{1}[23478]{1})|([4]{1}[7]{1})|([7]{1}[8]{1}))[0-9]{8}$";
    public static final String LT_STRING = "^[1]{1}(([3]{1}[0-2]{1})|([5]{1}[56]{1})|([8]{1}[56]{1})|([4]{1}[5]{1})|([7]{1}[6]{1}))[0-9]{8}$";
    public static final String DX_STRING = "^[1]{1}(([3]{1}[3]{1})|([5]{1}[3]{1})|([8]{1}[09]{1})|([7]{1}[37]{1}))[0-9]{8}$";
 
    public static final int YD = 1;
    public static final int LT = 2;
    public static final int DX = 3;
    public static final int DEFAULT = -1;
 
    /**
     * 查询手机号运营商
     *
     * @param phoneNum
     * @return 运营商类型
     */
    public static int checkOperator(String phoneNum) {
 
        if (phoneNum.length() == 11) {
            if (phoneNum.matches(YD_STRING)) {
                return YD;
            } else if (phoneNum.matches(LT_STRING)) {
                return LT;
            } else if (phoneNum.matches(DX_STRING)) {
                return DX;
            }
        }
 
        return DEFAULT;
    }
 
}


阅读 134+

一片空白

父爱如山,不善表达。回想十多年前,总记得父亲有个宽厚的肩膀,小小的自己跨坐在上面,越过人山人海去看更广阔的天空,那个时候期望自己有一双翅膀,能够像鸟儿一样飞得高,看得远。虽然父亲有时会和自己开玩笑,但在做错事的时候会受到严厉的训斥。父亲有双粗糙的大手掌。