iOS--判断字符串NSString中数字、中文、大小写英文

iOS--判断字符串NSString中数字、中文、大小写英文

 
<iframe id="iframeu2051914_0" src="http://pos.baidu.com/vczm?sz=160x600&amp;rdid=2051914&amp;dc=2&amp;di=u2051914&amp;dri=0&amp;dis=0&amp;dai=2&amp;ps=5x30&amp;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&amp;dcb=BAIDU_SSP_define&amp;dtm=HTML_POST&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1471231003546&amp;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&amp;ari=2&amp;dbv=0&amp;drs=1&amp;pcs=1607x880&amp;pss=1607x278&amp;cfv=0&amp;cpl=2&amp;chi=1&amp;cce=true&amp;cec=UTF-8&amp;tlm=1471198603&amp;rw=880&amp;ltu=http%3A%2F%2Fwww.aichengxu.com%2Fview%2F72522&amp;ltr=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DdXNKc_X62kx8yURIdUJ2eodPZqKrnIz33u11CJtbrSr2rXB569P1lAUcgfvPSmii%26wd%3D%26eqid%3Da539101f00142f4b0000000457b13410&amp;ecd=1&amp;psr=1920x1080&amp;par=1920x977&amp;pis=-1x-1&amp;ccd=24&amp;cja=true&amp;cmi=4&amp;col=ja-jp&amp;cdo=-1&amp;tcn=1471231004&amp;qn=b38d5bec7821bf0c&amp;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&amp;rdid=2341972&amp;dc=2&amp;di=u2341972&amp;dri=0&amp;dis=0&amp;dai=3&amp;ps=263x338&amp;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&amp;dcb=BAIDU_SSP_define&amp;dtm=HTML_POST&amp;dvi=0.0&amp;dci=-1&amp;dpt=none&amp;tsr=0&amp;tpr=1471231003546&amp;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&amp;ari=2&amp;dbv=0&amp;drs=1&amp;pcs=1607x880&amp;pss=1607x283&amp;cfv=0&amp;cpl=2&amp;chi=1&amp;cce=true&amp;cec=UTF-8&amp;tlm=1471198603&amp;rw=880&amp;ltu=http%3A%2F%2Fwww.aichengxu.com%2Fview%2F72522&amp;ltr=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DdXNKc_X62kx8yURIdUJ2eodPZqKrnIz33u11CJtbrSr2rXB569P1lAUcgfvPSmii%26wd%3D%26eqid%3Da539101f00142f4b0000000457b13410&amp;ecd=1&amp;psr=1920x1080&amp;par=1920x977&amp;pis=-1x-1&amp;ccd=24&amp;cja=true&amp;cmi=4&amp;col=ja-jp&amp;cdo=-1&amp;tcn=1471231004&amp;qn=49560e353b12e796&amp;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(@"整形或浮点型"); } 

 

 

转载于:https://www.cnblogs.com/LiLihongqiang/p/5893395.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值