是否是汉字

//如果输入的昵称是字母,判断是否合格

        if(self.nickNameText){

            for (int i=0; i<self.nickNameText.length; i++) {

                NSRange range=NSMakeRange(i,1);

                NSString *subString=[self.nickNameTextsubstringWithRange:range];

                const char *cString=[subString UTF8String];

                if (strlen(cString)==3)

                {

                    NSLog(@"昵称是汉字");

                    if(self.nickNameText.length<2||self.nickNameText.length>8){

                        UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:@"不要输入低于2个或者高于8" message:@"您输入的昵称格式有误,请重新输入" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定"nil];

                        [alertView show];

                        return;

                    }

                }else if(strlen(cString)==1)

                {

                    NSLog(@"昵称是字母");

                   if(self.nickNameText.length<4||self.nickNameText.length>16){

                        UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:@"不要输入低于4个或者高于16" message:@"您输入的昵称格式有误"delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定"nil];

                        [alertView show];

                        return;

                    }

                }

            }

        }

你可能感兴趣的:(是否是汉字)