您的位置:首页 > 移动开发 > IOS开发

iOS开发判断手机号格式

2016-01-07 15:39 489 查看
// 判断手机号格式 可以写成NSString的Expense

- (BOOL)isCorrectTelOrPhone:(BOOL)allCheck

{

if ([NSString
isNil:self]) {

return YES;

}

NSString *regex =
@"^(130|131|132|133|134|135|136|137|138|139|150|151|152|153|155|156|157|158|159|177|180|181|182|183|184|185|186|187|188|189)\\d{8}$";

NSPredicate *pred = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", regex];

NSString *other;

if (allCheck) {

other = @"^(0[0-9]{2,3}\\-)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$";

NSPredicate *otherPred = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", other];

if ([otherPred
evaluateWithObject:self]) {

return
YES;

}

}

BOOL isMatch = [pred
evaluateWithObject:self];

return isMatch;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: