Android手机号校验(包含166,199开头)

最近在做手机号校验,在此记录一下,希望帮助更多的人。
/** * 匹配手机号的规则:[3578]是手机号第二位可能出现的数字 */

public static final String REGEX_MOBILE = "^[1][3578][0-9]{9}$";

1、手机号开头集合

166,

176,177,178

180,181,182,183,184,185,186,187,188,189

145,147

130,131,132,133,134,135,136,137,138,139

150,151,152,153,155,156,157,158,159

198,199

2、正则表达式

public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {

String regExp = "^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147,145))\\d{8}$";

Pattern p = Pattern.compile(regExp);

Matcher m = p.matcher(str);

return m.matches();

}

包含的手机号整理有

13开头的后面跟0-9的任意8位数;

15开头的后面跟除了4以外的0-9的任意8位数;

18开头的后面跟0-9的任意8位数;

17开头的后面跟0-8的任意8位数,或者17[^9];

147,145开头后面跟任意8位数;

166开头的后面跟任意8位数;

198,199开头后面跟任意8位数;

猜你喜欢

转载自blog.csdn.net/lou_liang/article/details/81477379
今日推荐