1、数字字符校验
#define NUMBERSPERIOD @"0123456789."
- (BOOL)CheckInput:(NSString *)string {
NSCharacterSet *cs;
cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSPERIOD] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
BOOL basicTest = [string isEqualToString:filtered];
return basicTest;
}
2、判断用户名,在2-16位
- (BOOL)CheckInput:(NSString *)text {
NSString*Regex = @"^\\w{2,16}{1}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];
return [emailTest evaluateWithObject:text];
}
3、判断手机号码,1开头的十一位数字
- (BOOL)CheckInput:(NSString *)text {
NSString *Regex = @"1\\d{10}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];
return [emailTest evaluateWithObject:text];
}
4、判断邮箱
- (BOOL)CheckInput:(NSString *)text {
NSString *Regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];
return [emailTest evaluateWithObject:text];
}
5、判断密码,6-16位
- (BOOL)CheckInput:(NSString *)text
{
NSString *Regex = @"\\w{6,16}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];
return [emailTest evaluateWithObject:text];
}