输入汉字或者英文位数较应
2016-03-30 10:10
197 查看
//如果输入的昵称是字母,判断是否合格
if(cell00.mTextField.text){
for (int i=0; i<cell00.mTextField.text.length;
i++) {
NSRange range=NSMakeRange(i,1);
NSString *subString=[cell00.mTextField.text
substringWithRange:range];
const
char *cString=[subString UTF8String];
if (strlen(cString)==3)
{
DLog(@"昵称是汉字");
if(cell00.mTextField.text.length<2||cell00.mTextField.text.length>6){
UIAlertView *alertView=[[UIAlertView
alloc]initWithTitle:@"请输入2到6个汉字"
message:@"您输入的格式有误,请重新输入"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
[alertView show];
return;
}
}else
if(strlen(cString)==1)
{
DLog(@"昵称是字母");
if(cell00.mTextField.text.length<4||cell00.mTextField.text.length>20){
UIAlertView *alertView=[[UIAlertView
alloc]initWithTitle:@"请输入4到20个字母和数字"
message:@"您输入的格式有误"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
[alertView show];
return;
}
}
}
}
首先判断用户输入的是汉字还是字母数字,但是混合的汉字和字母是没法较应的(只能根据text.length)
if(cell00.mTextField.text){
for (int i=0; i<cell00.mTextField.text.length;
i++) {
NSRange range=NSMakeRange(i,1);
NSString *subString=[cell00.mTextField.text
substringWithRange:range];
const
char *cString=[subString UTF8String];
if (strlen(cString)==3)
{
DLog(@"昵称是汉字");
if(cell00.mTextField.text.length<2||cell00.mTextField.text.length>6){
UIAlertView *alertView=[[UIAlertView
alloc]initWithTitle:@"请输入2到6个汉字"
message:@"您输入的格式有误,请重新输入"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
[alertView show];
return;
}
}else
if(strlen(cString)==1)
{
DLog(@"昵称是字母");
if(cell00.mTextField.text.length<4||cell00.mTextField.text.length>20){
UIAlertView *alertView=[[UIAlertView
alloc]initWithTitle:@"请输入4到20个字母和数字"
message:@"您输入的格式有误"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
[alertView show];
return;
}
}
}
}
首先判断用户输入的是汉字还是字母数字,但是混合的汉字和字母是没法较应的(只能根据text.length)
相关文章推荐
- GUID批量生成
- 以前的东西整理(6)
- Android 学习笔记
- install torch7 on centos6.5
- Cell展开&&收缩全垒打
- 软件版本的含义
- Quoted-Printable编码原理及代码实现
- Linux kernel的中断子系统之(一):综述
- Apache Lucene 新手使用指南
- 毛泽东时代是中国历史上最伟大的时代——为纪念伟大领袖毛主席逝世三十二周年而作
- 了解中国国家领导人饮食养生提高自身健康!
- 0基础学习 opencv
- 数论(1):最大公约数和最小公倍数(Gcd&Lcm)
- osg读取文件的原理(插件工作机制)
- 基于netty的企业即时通讯系统的设计与实-服务器消息重发
- SpringMVC小结
- zabbix监控安装
- 3月西部数码.wang域名注册量报告:净增长量超10万
- c++ vector 迭代器 demo
- 安装永中office 2009个人版 点快捷方式无法运行