iOS--判断字符串NSString中数字、中文、大小写英文
iOS--判断字符串NSString中数字、中文、大小写英文
<iframe id="iframeu2051914_0" src="http://pos.baidu.com/vczm?sz=160x600&rdid=2051914&dc=2&di=u2051914&dri=0&dis=0&dai=2&ps=5x30&coa=at%3D3%26rsi0%3D160%26rsi1%3D600%26pat%3D6%26tn%3DbaiduCustNativeAD%26rss1%3D%2523FFFFFF%26conBW%3D1%26adp%3D1%26ptt%3D0%26titFF%3D%2525E5%2525BE%2525AE%2525E8%2525BD%2525AF%2525E9%25259B%252585%2525E9%2525BB%252591%26titFS%3D14%26rss2%3D%2523000000%26titSU%3D0%26ptbg%3D90%26piw%3D0%26pih%3D0%26ptp%3D0&dcb=BAIDU_SSP_define&dtm=HTML_POST&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1471231003546&ti=iOS--%E5%88%A4%E6%96%AD%E5%AD%97%E7%AC%A6%E4%B8%B2NSString%E4%B8%AD%E6%95%B0%E5%AD%97%E3%80%81%E4%B8%AD%E6%96%87%E3%80%81%E5%A4%A7%E5%B0%8F%E5%86%99%E8%8B%B1%E6%96%87%20-%20%E7%88%B1%E7%A8%8B%E5%BA%8F%E7%BD%91&ari=2&dbv=0&drs=1&pcs=1607x880&pss=1607x278&cfv=0&cpl=2&chi=1&cce=true&cec=UTF-8&tlm=1471198603&rw=880&ltu=http%3A%2F%2Fwww.aichengxu.com%2Fview%2F72522&ltr=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DdXNKc_X62kx8yURIdUJ2eodPZqKrnIz33u11CJtbrSr2rXB569P1lAUcgfvPSmii%26wd%3D%26eqid%3Da539101f00142f4b0000000457b13410&ecd=1&psr=1920x1080&par=1920x977&pis=-1x-1&ccd=24&cja=true&cmi=4&col=ja-jp&cdo=-1&tcn=1471231004&qn=b38d5bec7821bf0c&tt=1471231003536.247.324.324" width="160" height="600" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="border-width: 0px; vertical-align: bottom; margin: 0px;"></iframe>
<iframe id="iframeu2341972_0" src="http://pos.baidu.com/vczm?sz=600x250&rdid=2341972&dc=2&di=u2341972&dri=0&dis=0&dai=3&ps=263x338&coa=at%3D3%26rsi0%3D600%26rsi1%3D250%26pat%3D6%26tn%3DbaiduCustNativeAD%26rss1%3D%2523FFFFFF%26conBW%3D0%26adp%3D1%26ptt%3D0%26titFF%3D%2525E5%2525BE%2525AE%2525E8%2525BD%2525AF%2525E9%25259B%252585%2525E9%2525BB%252591%26titFS%3D14%26rss2%3D%2523000000%26titSU%3D0%26ptbg%3D90%26piw%3D0%26pih%3D0%26ptp%3D0&dcb=BAIDU_SSP_define&dtm=HTML_POST&dvi=0.0&dci=-1&dpt=none&tsr=0&tpr=1471231003546&ti=iOS--%E5%88%A4%E6%96%AD%E5%AD%97%E7%AC%A6%E4%B8%B2NSString%E4%B8%AD%E6%95%B0%E5%AD%97%E3%80%81%E4%B8%AD%E6%96%87%E3%80%81%E5%A4%A7%E5%B0%8F%E5%86%99%E8%8B%B1%E6%96%87%20-%20%E7%88%B1%E7%A8%8B%E5%BA%8F%E7%BD%91&ari=2&dbv=0&drs=1&pcs=1607x880&pss=1607x283&cfv=0&cpl=2&chi=1&cce=true&cec=UTF-8&tlm=1471198603&rw=880&ltu=http%3A%2F%2Fwww.aichengxu.com%2Fview%2F72522&ltr=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DdXNKc_X62kx8yURIdUJ2eodPZqKrnIz33u11CJtbrSr2rXB569P1lAUcgfvPSmii%26wd%3D%26eqid%3Da539101f00142f4b0000000457b13410&ecd=1&psr=1920x1080&par=1920x977&pis=-1x-1&ccd=24&cja=true&cmi=4&col=ja-jp&cdo=-1&tcn=1471231004&qn=49560e353b12e796&tt=1471231003536.251.470.470" width="600" height="250" align="center,center" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="border-width: 0px; vertical-align: bottom; margin: 0px;"></iframe>
iOS--判断字符串NSString中数字、中文、大小写英文,有需要的朋友可以参考下。
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(@"整形或浮点型");
}