1、设置4-14位的英文和数字输入
NSString *regex = @"^[A-Za-z0-9]{4,14}$"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; BOOL isMatch = [pred evaluateWithObject:text];
2、判断是否全数字,非正则
NSScanner* scan = [NSScanner scannerWithString:str]; int val; return [scan scanInt:&val] && [scan isAtEnd];
3、判断是否是邮箱格式
NSString *regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; BOOL result = [emailTest evaluateWithObject:email];