male
どちらかまたはのみを受け入れるには、Objective Cの正規表現が必要です。これは、下位と上位の両方を受け入れることfemale
ができるcase-Insensitive
手段である必要があります。アップルのドキュメントを調べました。以下のコードを実装しましたが、機能しません。
->男性または女性のみが受け入れられます
-(BOOL)genderValidate:(NSString *)string{
NSError *error=nil;
NSRegularExpression *regex =[NSRegularExpression regularExpressionWithPattern:@"\\b (m|f)(a|e)(l|m)(e|a)(l)(e) \\b" options:(NSRegularExpressionCaseInsensitive) error: &error];
NSUInteger numberofmatches =[regex numberOfMatchesInString:string options:0 range:NSMakeRange(0,[string length])];
return numberofmatches;
}