美文网首页
textFeild textView 输入无效字符

textFeild textView 输入无效字符

作者: 寒雨晚风 | 来源:发表于2019-06-14 16:48 被阅读0次

    - (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;

    }

    相关文章

      网友评论

          本文标题:textFeild textView 输入无效字符

          本文链接:https://www.haomeiwen.com/subject/sympfctx.html