输入汉字或者英文位数较应

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

    if(cell00.mTextField.text){

        

        for (int i=0; i<cell00.mTextField.text.length; i++) {

            

            NSRange range=NSMakeRange(i,1);

            

            NSString *subString=[cell00.mTextField.text substringWithRange:range];

            

            const char *cString=[subString UTF8String];

            

            if (strlen(cString)==3)

                

            {

                

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

              

                

                if(cell00.mTextField.text.length<2||cell00.mTextField.text.length>6){

                    

                    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"请输入26个汉字" message:@"您输入的格式有误,请重新输入" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

                    

                    [alertView show];

                    

                    return;

                    

                }

                

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

                

            {

                

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

               


                if(cell00.mTextField.text.length<4||cell00.mTextField.text.length>20){

                    

                    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"请输入420个字母和数字" message:@"您输入的格式有误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

                    

                    [alertView show];

                    

                    return;

                    

                }

                

            }

            

        }

        

    }


首先判断用户输入的是汉字还是字母数字,但是混合的汉字和字母是没法较应的(只能根据text.length)

你可能感兴趣的:(输入汉字或者英文位数较应)