Home >Web Front-end >JS Tutorial >How to determine whether to input in ios using regular expressions
This time I will show you how to use regular expressions to determine whether to input in ios, and how to determine whether to input in regular expressions in ios.
can only be Chinese-(BOOL)onlyInputChineseCharacters:(NSString*)string{
NSString *zhString = @"[\u4e00-\u9fa5]+";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",zhString];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)onlyInputTheNumber:(NSString*)string{
NSString *numString =@"[0-9]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",numString];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)onlyInputLowercaseLetter:(NSString*)string{
NSString *regex =@"[a-z]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)onlyInputACapital:(NSString*)string{
NSString *regex =@"[A-Z]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)InputCapitalAndLowercaseLetter:(NSString*)string{
NSString *regex =@"[a-zA-Z]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)inputLettersOrNumbers:(NSString*)string{
NSString *regex =@"[a-zA-Z0-9]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
-(BOOL)inputNumberOrLetters:(NSString*)name {
NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";
NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
BOOL inputString = [userNamePredicate evaluateWithObject:name];
return inputString;
}
- (BOOL)inputChineseOrNumbers:(NSString*)string{
NSString *regex =@"[\u4e00-\u9fa5]+[0-9]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)inputChineseOrNumbersLimit:(NSString*)string{
NSString *regex =@"[\u4e00-\u9fa5][0-9]{6,20}+$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)inputChineseOrLettersAndNumbersNum:(NSString*)string{
NSString *regex =@"[\u4e00-\u9fa5]+[A-Za-z0-9]*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
- (BOOL)inputChineseOrLettersNumberslimit:(NSString*)string{
NSString *regex =@"[\u4e00-\u9fa5]+[A-Za-z0-9]{6,20}+$";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
BOOL inputString = [predicate evaluateWithObject:string];
return inputString;
}
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other php Chinese websites related articles!
Recommended reading:
How to write a regular expression to match a group of charactersDetailed explanation of positional matching of regular expressionsThe above is the detailed content of How to determine whether to input in ios using regular expressions. For more information, please follow other related articles on the PHP Chinese website!