您的位置:首页 > 其它

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

2016-03-30 10:10 197 查看
//如果输入的昵称是字母,判断是否合格
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: