iOS 郵箱正則表達式。
//進行郵箱正則表達式判斷-(BOOL) validateEmail { NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; return [emailTest evaluateWithObject:self]; }
這裡面的self 是因為這個方法是寫在category的 NSString + SiZheString.m 中
所以調取方式應該是
if([@"字符串" validateEmail]){ }
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; Bool isTrue = [emailTest evaluateWithObject:@"字符串"];