Nonsense don't say that directly on the code
#pragmaMark-Chinese character judge-(BOOL) Validatecontainschinese: (NSString *) content{nsregularexpression*regularexpression =[[Nsregularexpression alloc] Initwithpattern:@"^[\u4e00-\u9fa5]"options:nsregularexpressioncaseinsensitive Error:nil]; return([RegularExpression numberofmatchesinstring:content Options:nsmatchingr Eportprogress Range:nsmakerange (0, content.length)] >0);}//whether the match is a full Chinese-(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];}//using rangeofstring:option: Direct lookup-(BOOL) Validaterangecontainschinese: (NSString *) content{NSString*regex =@"^[\u4e00-\u9fa5]"; Nsrange Range=[content Rangeofstring:regex Options:nsregularexpressionsearch]; returnrange.length; }//using rangeofstring:option: Direct lookup-(BOOL) Validaterangeallchinese: (NSString *) content{NSString*regex =@"^[\u4e00-\u9fa5]+s"; Nsrange Range=[content Rangeofstring:regex Options:nsregularexpressionsearch]; returnrange.length; }
Normal nsregularexpression predicate nspredicate and Nsrange are judged by text characters in IOS