- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string
{
if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) {
return NO;//此处是限制emoji表情输入
}
return YES;
}
-(BOOL)textView:(UITextView*)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
if ([[[textView textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textView textInputMode] primaryLanguage]) {
return NO;//此处是限制emoji表情输入
}
return YES;
}
只输入字母
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string
{
return[selfvalidateNumber:string];
}
- (BOOL)validateNumber:(NSString*)number {
BOOLres =YES;
NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
inti = 0;
while(i < number.length) {
NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
NSRangerange = [stringrangeOfCharacterFromSet:tmpSet];
if(range.length== 0) {
res =NO;
break;
}
i++;
}
returnres;
}