正则表达式
^1(3[0-9]|4[579]|5[^4]|8[0-9]|7[0135678])\\d{8}$
iOS使用方法
+ (BOOL)checkPhoneNumber:(NSString *)phoneNumber{
/*
** 电信号段:133/153/180/181/189/177
** 联通号段:130/131/132/155/156/185/186/145/176
** 移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
** 虚拟运营商:170
*/
NSString *MOBILE = @"^1(3[0-9]|4[579]|5[^4]|8[0-9]|7[0135678])\\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
return [regextestmobile evaluateWithObject:phoneNumber];
}
Android使用方法:
public static boolean isMobileNO(String mobileNums) {
/*
** 电信号段:133/153/180/181/189/177
** 联通号段:130/131/132/155/156/185/186/145/176
** 移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/149/178
** 虚拟运营商:170
*/
String telRegex = "^(1(3[0-9])|(4[5,7,9])|(5[^4])|(8[0-9])|(7[0,1,3,5,6,7,8]))\\d{8}$";
if (TextUtils.isEmpty(mobileNums))
return false;
else
return mobileNums.matches(telRegex);
}
java使用方法:
public static boolean isMobileNO(String mobiles) {
boolean flag = false;
try {
Pattern p = Pattern
.compile("^(1(3[0-9])|(4[5,7,9])|(5[^4])|(8[0-9])|(7[0,1,3,5,6,7,8]))\\d{8}$");
Matcher m = p.matcher(mobiles);
flag = m.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
网友评论