直接看代码吧!!!
#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;}
以上所述是小编给大家介绍的Android 判断是否是是全汉字、全字母、全数字、数字和字母等,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!
新闻热点
疑难解答