//如果输入的昵称是字母,判断是否合格
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:@"请输入2到6个汉字" 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:@"请输入4到20个字母和数字" message:@"您输入的格式有误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView show];
return;
}
}
}
}
首先判断用户输入的是汉字还是字母数字,但是混合的汉字和字母是没法较应的(只能根据text.length)