判断用户名为汉字

2015-12-28  本文已影响97人  林步蜓
            NSString *userIdStr=@“a&*林”;
            int utfCode = 0;
            void *buffer = &utfCode;
            NSRange range = NSMakeRange(userIdStr.length - 1, 1);
            NSString *word = [userIdStr substringWithRange:range];
            BOOL b = [word getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL];
            if (b && (utfCode >= 0x4e00 && utfCode <= 0x9fa5)) {
                NSLog(@"it is chinese,%@", word);
            }else{
                isChecked = NO;
                errorMessage = @"用户名必须为汉字";
            
            }
上一篇下一篇

猜你喜欢

热点阅读