xcode怎样才能使text中只能输入数字和字母
xcode吧
全部回复
仅看楼主
level 1
aligaduoyimas 楼主
今天老师让设计一个登录界面,要求只能输入字母和数字,不会编程怎么办,求教啊
2013年07月02日 07点07分 1
level 3
Ja_
我的想法是,if语句判断ascii码,如果在数字和字母的范围之内就正常读入
2013年07月09日 13点07分 2
字符串中每个都判断,是不是用FOR循环,刚接触苹果机,真是瞬间变古人
2013年07月10日 01点07分
Ja_
不用的,你只要一个范围就可以了,因为数字、大写字母、小写字母的ASCII码是连续的,只要输入的在这三个范围之内就可以了
2013年07月10日 09点07分
level 1
锁定字母数字键盘不让换
2013年07月20日 12点07分 3
level 11
正则表达式
2013年09月20日 14点09分 4
level 2

NSCharacterSet *nameCharacters = [[NSCharacterSet
characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]invertedSet];
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSCharacterSet *nameCharacters = [[NSCharacterSet
characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]invertedSet];
//过滤掉不是字母数字的字符
NSString* getString = [string stringByTrimmingCharactersInSet:set];
// NSString* getString =[[string componentsSeparatedByCharactersInSet:set] componentsJoinedByString:@""];
if ([getString isEqualToString:string]) {
return YES;
}
return NO;
}
2013年09月27日 01点09分 5
1