標籤:
//如果輸入的暱稱是字母,判斷是否合格
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=[subStringUTF8String];
if (strlen(cString)==3)
{
NSLog(@"暱稱是漢字");
if(self.nickNameText.length<2||self.nickNameText.length>8){
UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:@"不要輸入低於2個或者高於8個"message:@"您輸入的暱稱格式有誤,請重新輸入"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"確定",nil];
[alertViewshow];
return;
}
}elseif(strlen(cString)==1)
{
NSLog(@"暱稱是字母");
if(self.nickNameText.length<4||self.nickNameText.length>16){
UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:@"不要輸入低於4個或者高於16個"message:@"您輸入的暱稱格式有誤"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"確定",nil];
[alertViewshow];
return;
}
}
}
}
iOS 怎麼判斷字串是漢字還是字母