iOS--判断字符串NSString中数字、中文、大小写英文
2015-09-17 10:14
465 查看
NSString *testString = @"中文123ljfLJF"; NSInteger alength = [testString length]; for (int i = 0; i<alength; i++) { char commitChar = [testString characterAtIndex:i]; NSString *temp = [testString substringWithRange:NSMakeRange(i,1)]; const char *u8Temp = [temp UTF8String]; if (3==strlen(u8Temp)){ NSLog(@"字符串中含有中文"); }else if((commitChar>64)&&(commitChar<91)){ NSLog(@"字符串中含有大写英文字母"); }else if((commitChar>96)&&(commitChar<123)){ NSLog(@"字符串中含有小写英文字母"); }else if((commitChar>47)&&(commitChar<58)){ NSLog(@"字符串中含有数字"); }else{ NSLog(@"字符串中含有非法字符"); } }
//判断是否为整形: - (BOOL)isPureInt:(NSString*)string{ NSScanner* scan = [NSScanner scannerWithString:string]; int val; return[scan scanInt:&val] && [scan isAtEnd]; } //判断是否为浮点形: - (BOOL)isPureFloat:(NSString*)string{ NSScanner* scan = [NSScanner scannerWithString:string]; float val; return[scan scanFloat:&val] && [scan isAtEnd]; } if( ![self isPureInt:textField.text] || ![self isPureFloat:textField.text]){ textField.textColor = [UIColor redColor]; textField.text = @"警告:含非法字符,请输入纯数字!"; return; }else{ NSLog(@"整形或浮点型"); }
相关文章推荐
- iOS夯实:RunLoop
- 在Android上山寨了一个Ios9的LivePhotos,放Github上了
- iOS学习——常用博客
- iOS 时间转换总结
- ios webView 加载本地html5
- iOS 9.0系统策略更新
- iOS - 强制旋转屏幕之代码实现
- iOS开发中最基本的位置功能实现示例
- iOS证书过期后,xcode打包ipa闪退。使用控制台方式来打包
- iOS CLLocationManager定位
- ios8.0下CLLocationManager定位服务需要授权了
- 【投稿】iOS 蓝牙开发(二)iOS 连接外设的代码实现
- iOS 中关于copy和mutable copy的理解
- iOS疯狂讲解之复杂对象的归档与反归档
- IOS定位服务的应用
- iOS开发之MapKit
- IOS学的容易----ARC与MRC 的切换
- 蓝懿iOS培训日志14 测试日及测试总结
- 个人收集的iOS开源动画-----长期跟新
- ios 判断字符串为空和只为空格解决办法