[分享]iOS开发-限制输入特殊字符

-(void)viewDidLoad
{
        self.specialStringArray = [@[] mutableCopy];
        NSString * string = @"~,¥,#,&,*,<,>,《,》,(,),[,],{,},【,】,^,@,/,£,¤,,|,§,¨,「,」,『,』,¢,¬, ̄,(,),——,+,|,$,_,€,¥";
        self.specialStringArray = [string componentsSeparatedByString:@","];
}
//在需要的地方调用该方法
-(void)submit
{
        NSString * intriduction = self.textField.text;
        for (NSInteger i = 0; i < self.specialStringArray.count; i ++) {
      //判断字符串中是否含有特殊符号
        if ([intriduction rangeOfString:self.specialStringArray[i]].location != NSNotFound) {
            [MyUtil showTipText:@"请不要输入特殊符号" completion:^{
                [self.textVew becomeFirstResponder];
            }];
            return;
        }
    }
}
    原文作者:ShevaKuilin
    原文地址: https://segmentfault.com/a/1190000006679082
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞