//如果输入的昵称是字母,判断是否合格
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;
}
}
}
}
本文介绍了一个用于检查用户输入昵称格式正确性的算法实现。该算法能够判断输入的昵称是否为2到6个汉字或者4到20个字母和数字,并在格式不正确时给出提示。
4029

被折叠的 条评论
为什么被折叠?



