/*!
* 是否为电话号码【简单写法】
*
* @param pattern 传入需要检测的字符串
*
* @return 返回检测结果 是或者不是
*/
+(BOOL)SJ_isPhoneNumber:(NSString *)phoneNum
{
NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|70)\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
return [regextestmobile evaluateWithObject:phoneNum];
}
/*!
* 是否为电话号码【复杂写法】
*
* @param pattern 传入需要检测的字符串
*
* @return 返回检测结果 是或者不是
*/
+ (BOOL)SJ_isMobileNumber:(NSString *)mobileNum
{
if (mobileNum.length != 11)
{
return NO;
}
/**
* 手机号码:
* 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[6, 7, 8], 18[0-9], 170[0-9]
* 移动号段: 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705
* 联通号段: 130,131,132,155,156,185,186,145,176,1709
* 电信号段: 133,153,180,181,189,177,1700
*/
NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|70)\d{8}$";
/**
* 中国移动:China Mobile
* 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705
*/
NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\d{8}$)|(^1705\d{7}$)";
/**
* 中国联通:China Unicom
* 130,131,132,155,156,185,186,145,176,1709
*/
NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\d{8}$)|(^1709\d{7}$)";
/**
* 中国电信:China Telecom
* 133,153,180,181,189,177,1700
*/
NSString *CT = @"(^1(33|53|77|8[019])\d{8}$)|(^1700\d{7}$)";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
if (([regextestmobile evaluateWithObject:mobileNum] == YES)
|| ([regextestcm evaluateWithObject:mobileNum] == YES)
|| ([regextestct evaluateWithObject:mobileNum] == YES)
|| ([regextestcu evaluateWithObject:mobileNum] == YES))
{
return YES;
}
else
{
return NO;
}
//
// //验证方法2
// /**
// * 手机号码
// * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
// * 联通:130,131,132,152,155,156,185,186
// * 电信:133,1349,153,180,189
// */
// // NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\d{8}$";
//
//
// /**
// * 中国移动:China Mobile
// * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
// */
// // NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\d)\d{7}$"; // China Mobile phoneNum
//
// /**
// * 中国联通:China Unicom
// * 130,131,132,152,155,156,185,186
// */
// // NSString * CU = @"^1(3[0-2]|5[256]|8[56])\d{8}$"; // China Unicom phoneNum
//
//
// /**
// * 中国电信:China Telecom
// * 133,1349,153,180,189
// */
// // NSString * CT = @"^1((33|53|8[09])[0-9]|349)\d{7}$"; // China Telecom phoneNum
//
// /**
// * The following 4 predicate can tell which carrier the number is from.
// */
// // NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
// // NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
// // NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
// // NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
//
//
// //Only Check if the string is a valid telephone number, ignoring the carrier info.
//
// NSString *isMobileRegex = @"^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0,5-9]{1}))+\d{8})$";
//
//
// // NSString *isMobileRegex = @"^((\+86)|(\(\+86\)))?(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0,5-9]{1}))+\d{8})$";
//
//
// NSPredicate *mobileRegex = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", isMobileRegex];
//
// if (([mobileRegex evaluateWithObject:telephoneNum] == YES))
// {
// return YES;
//
// }else{
// return NO;
// }
//
}
/*!
* 判断是否是:移动手机号
*
* @param phoneNum 手机号码
*
* @return 移动手机号
*/
+ (BOOL)SJ_isChinaMobile:(NSString *)phoneNum
{
/*!
* 中国移动:China Mobile
* 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705
*/
NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\d{8}$)|(^1705\d{7}$)";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
return [regextestcm evaluateWithObject:phoneNum];
}
/*!
* 判断是否是:联通手机号
*
* @param phoneNum 手机号码
*
* @return 联通手机号
*/
+ (BOOL)SJ_isChinaUnicom:(NSString *)phoneNum
{
/*!
* 中国联通:China Unicom
* 130,131,132,155,156,185,186,145,176,1709
*/
NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\d{8}$)|(^1709\d{7}$)";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
return [regextestcm evaluateWithObject:phoneNum];
}
/*!
* 判断是否是:电信手机号
*
* @param phoneNum 手机号码
*
* @return 电信手机号
*/
+ (BOOL)SJ_isChinaTelecom:(NSString *)phoneNum
{
/*!
* 中国电信:China Telecom
* 133,153,180,181,189,177,1700
*/
NSString *CT = @"^1((33|53|8[019])[0-9]|349)\d{7}$";
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
return [regextestcm evaluateWithObject:phoneNum];
}
/*!
* 判断具体是哪个运营商的手机号
*
* @param phoneNum 传入需要检测的字符串
*
* @return 返回:中国移动、中国联通、中国电信、未知
*/
+ (NSString *)SJ_getPhoneNumType:(NSString *)phoneNum
{
return [SJRegularExpression SJ_isChinaMobile:phoneNum]? @"中国移动": ([SJRegularExpression SJ_isChinaUnicom:phoneNum]? @"中国联通":([SJRegularExpression SJ_isChinaTelecom:phoneNum]? @"中国电信": @"未知号码"));
}
/*!
* 检测是否为邮箱
*
* @param pattern 传入需要检测的字符串
*
* @return 返回检测结果 是或者不是
*/
+ (BOOL)SJ_isEmailQualified:(NSString *)emailStr
{
NSString *pattern = @"[A-Z0-9a-z._%+-]/*!
* 是否为电话号码【简单写法】
*
* @param patte