正则表达式
^1(3[0-9]|4[57]|5[^4]|6[6]|7[0-8]|8[0-9]|9[8-9])\\d{8}$
iOS使用方法
+ (BOOL)checkPhoneNumber:(NSString *)phoneNumber{
NSString *MOBILE = @"^1(3[0-9]|4[57]|5[^4]|6[6]|7[0-8]|8[0-9]|9[8-9])\\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
return [regextestmobile evaluateWithObject:phoneNumber];
}
Android使用方法:
public static boolean isMobileNO(String mobileNums) {
String telRegex = "^((13[0-9])|(14[5,7])|(15[^4,\\D])|(166)|(17[0-8])|(18[^4,\\D])|(199)|(198))\\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("^((13[0-9])|(14[5,7])|(15[^4,\\D])|(166)|(17[0-8])|(18[^4,\\D])|(199)|(198))\\d{8}$");
Matcher m = p.matcher(mobiles);
flag = m.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}