正則表達(dá)式
^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{
/*
** 電信號(hào)段:133/153/180/181/189/177
** 聯(lián)通號(hào)段:130/131/132/155/156/185/186/145/176
** 移動(dòng)號(hào)段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
** 虛擬運(yùn)營(yíng)商:170
*/
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) {
/*
** 電信號(hào)段:133/153/180/181/189/177
** 聯(lián)通號(hào)段:130/131/132/155/156/185/186/145/176
** 移動(dòng)號(hào)段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/149/178
** 虛擬運(yùn)營(yíng)商:170
*/
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;
}