时间:2021-03-04 13:50:12 | 栏目:Android代码 | 点击:次
直接看代码吧!!!
#pragma mark 判断只能为中文的 - (BOOL) zsStringInputOnlyIsChinese:(NSString*)string { NSString *regex = @"[\u4e00-\u9fa5]+"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if ([pred evaluateWithObject:string]) { return YES; } return NO; } #pragma mark 判断只能为数字的 - (BOOL) zsStringInputOnlyIsNumber:(NSString*)string { NSString *regex =@"[0-9]*"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if ([pred evaluateWithObject:string]) { return YES; } return NO; } #pragma mark 判断只能为字母的 - (BOOL) zsStringInputOnlyIsLetter:(NSString*)string { NSString *regex =@"[a-zA-Z]*"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if ([pred evaluateWithObject:string]) { return YES; } return NO; }
#pragma mark 判断只能为字母或数字的 - (BOOL) zsStringInputOnlyIsNumber:(NSString*)string { NSString *regex =@"[a-zA-Z0-9]*"; NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if ([pred evaluateWithObject:string]) { return YES; } return NO; }