//驗(yàn)證手機(jī)號(hào)碼
+ (BOOL)validateMobile:(NSString*)mobile {
? ? if(mobile.length==0) {
? ? ? ? NSString *message = RCDLocalizedString(@"mobile_number_unempty");
? ? ? ? [self showAlertController:message cancelTitle:RCDLocalizedString(@"confirm")];
? ? ? ? returnNO;
? ? }
? ? //手機(jī)號(hào)以13, 15,18開頭,八個(gè) \d 數(shù)字字符
? ? NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
? ? NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
? ? if(![phoneTestevaluateWithObject:mobile]) {
? ? ? ? NSString *message = RCDLocalizedString(@"mobile_number_unempty");
? ? ? ? [self showAlertController:message cancelTitle:RCDLocalizedString(@"confirm")];
? ? ? ? returnNO;
? ? }
? ? return YES;
}
//驗(yàn)證電子郵箱
+ (BOOL)validateEmail:(NSString*)email {
? ? if(email.length==0) {
? ? ? ? returnNO;
? ? }
? ? NSString *expression = [NSString stringWithFormat:@"^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"];
? ? NSError*error =NULL;
? ? NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:expression
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? options:NSRegularExpressionCaseInsensitive
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? error:&error];
? ? NSTextCheckingResult *match = [regex firstMatchInString:email options:0 range:NSMakeRange(0, [email length])];
? ? if(!match) {
? ? ? ? returnNO;
? ? }
? ? return YES;
}