标签:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *checkString; if (range.location == 11) { return NO; }else{ if (![string isEqualToString:@""]) { checkString=[self.textfield.text stringByAppendingString:string]; }else{ checkString=[checkString stringByDeletingLastPathComponent]; } if ([self isMobileNumber:checkString]) { NSLog(@"号码满足"); }else{ NSLog(@"号码不满足"); } return YES; } }
- (BOOL)isMobileNumber:(NSString *)mobileNum { NSString * MOBILE = @"^((13[0-9])|(14[^4,\\D])|(15[^4,\\D])|(18[0-9]))\\d{8}$|^1(7[0-9])\\d{8}$"; NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE]; if ([regextestmobile evaluateWithObject:mobileNum] == YES){ return YES; }else{ return NO; } }
标签:
原文地址:http://my.oschina.net/u/2360693/blog/495610