#pragma - mark 只能为中文
-(BOOL)onlyInputChineseCharacters:(NSString*)string{
NSString *inputString =@"[\u4e00-\u9fa5]+";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,inputString];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 只能为数字
-
(BOOL)onlyInputTheNumber:(NSString*)string{
NSString numString =@"[0-9]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,numString];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 只能为小写
-
(BOOL)onlyInputLowercaseLetter:(NSString*)string{
NSString regex =@"[a-z]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 只能为大写
-
(BOOL)onlyInputACapital:(NSString*)string{
NSString regex =@"[A-Z]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 允许大小写
-
(BOOL)InputCapitalAndLowercaseLetter:(NSString*)string{
NSString regex =@"[a-zA-Z]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 允许含大小写或数字(不限字数)
-
(BOOL)inputLettersOrNumbers:(NSString*)string{
NSString regex =@"[a-zA-Z0-9]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 允许含大小写或数字(限字数)
-(BOOL)inputNumberOrLetters:(NSString*)name {
NSString *userNameRegex =@"1{6,20}+$";
NSPredicate *userNamePredicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,userNameRegex];
BOOL inputString = [userNamePredicateevaluateWithObject:name];
return inputString;
}
#pragma - mark 允许汉字或数字(不限字数)
-
(BOOL)inputChineseOrNumbers:(NSString*)string{
NSString regex =@"[\u4e00-\u9fa5]+[0-9]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 允许汉字或数字(限字数)
-
(BOOL)inputChineseOrNumbersLimit:(NSString*)string{
NSString *regex =@"[\u4e00-\u9fa5][0-9]{6,20}+$";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 允许汉字,大小写或数字(不限字数)
-
(BOOL)inputChineseOrLettersAndNumbersNum:(NSString*)string{
NSString regex =@"[\u4e00-\u9fa5]+[A-Za-z0-9]";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
#pragma - mark 允许汉字,大小写或数字(限字数)
-
(BOOL)inputChineseOrLettersNumberslimit:(NSString*)string{
NSString *regex =@"[\u4e00-\u9fa5]+[A-Za-z0-9]{6,20}+$";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@“SELF MATCHES %@”,regex];
BOOL inputString = [predicateevaluateWithObject:string];
return inputString;
}
A-Za-z0-9 ↩︎