//直接调用这个方法就行
-(int)checkIsHaveNumAndLetter:(NSString*)password{
//数字条件
NSRegularExpression*tNumRegularExpression = [NSRegularExpressionregularExpressionWithPattern:@"[0-9]"options:NSRegularExpressionCaseInsensitiveerror:nil];
//符合数字条件的有几个字节
NSUIntegertNumMatchCount = [tNumRegularExpressionnumberOfMatchesInString:password
options:NSMatchingReportProgress
range:NSMakeRange(0, password.length)];
//英文字条件
NSRegularExpression*tLetterRegularExpression = [NSRegularExpressionregularExpressionWithPattern:@"[A-Za-z]"options:NSRegularExpressionCaseInsensitiveerror:nil];
//符合英文字条件的有几个字节
NSUIntegertLetterMatchCount = [tLetterRegularExpressionnumberOfMatchesInString:passwordoptions:NSMatchingReportProgressrange:NSMakeRange(0, password.length)];
if(tNumMatchCount == password.length) {
//全部符合数字,表示沒有英文
return1;
}elseif(tLetterMatchCount == password.length) {
//全部符合英文,表示沒有数字
return2;
}elseif(tNumMatchCount + tLetterMatchCount == password.length) {
//符合英文和符合数字条件的相加等于密码长度
return3;
}else{
return4;
//可能包含标点符号的情況,或是包含非英文的文字,这里再依照需求详细判断想呈现的错误
}
}
//以某个字符串开头(T_Code:表的名字,code:字段的名字)
NSString*string = [NSStringstringWithFormat:@"SELECT * FROM T_Code WHERE code LIKE '%@%%'",searchText];
//包含有某个字符串
NSString*string = [NSString stringWithFormat:@"SELECT * FROM T_Code WHERE code LIKE '%%%@%%'",searchText];
//以某个字符串结尾
NSString*string = [NSString stringWithFormat:@"SELECT * FROM T_Code WHERE code LIKE '%%%@'",searchText];