标签:pattern chinese orm 代码 sch obj regular red regex
废话不说,直接上代码
#pragma mark - 中文字符判断 - (BOOL)validateContainsChinese:(NSString *)content { NSRegularExpression *regularexpression = [[NSRegularExpression alloc] initWithPattern:@"^[\u4e00-\u9fa5]" options:NSRegularExpressionCaseInsensitive error:nil]; return ([regularexpression numberOfMatchesInString:content options:NSMatchingReportProgress range:NSMakeRange(0, content.length)] > 0); } // 匹配是否为全中文 - (BOOL)validateAllChinese:(NSString *)content { NSString *regEx = @"^[\u4e00-\u9fa5]+$"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regEx]; return [predicate evaluateWithObject:content]; } - (BOOL)validateContainsChineseT:(NSString *)content { NSString *regEx = @"^[\u4e00-\u9fa5].+"; // @"^[\u4e00-\u9fa5].*" NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regEx]; return [predicate evaluateWithObject:content]; } // 利用rangeOfString:option:直接查找 - (BOOL)validateRangeContainsChinese:(NSString *)content { NSString *regEx = @"^[\u4e00-\u9fa5]"; NSRange range = [content rangeOfString:regEx options:NSRegularExpressionSearch]; return range.length; } // 利用rangeOfString:option:直接查找 - (BOOL)validateRangeAllChinese:(NSString *)content { NSString *regEx = @"^[\u4e00-\u9fa5]+S"; NSRange range = [content rangeOfString:regEx options:NSRegularExpressionSearch]; return range.length; }
iOS 中文字符判断 正则NSRegularExpression 谓词NSPredicate 和 NSRange
标签:pattern chinese orm 代码 sch obj regular red regex
原文地址:http://www.cnblogs.com/pruple/p/7450654.html