1、限制输入的为汉字和字母
//正则表达式
#define NMUBERS @"0123456789./*-+~!@#$%^&()_+-=,./;'[]{}:<>?`"
NSCharacterSet *cs;
cs = [[NSCharacterSet characterSetWithCharactersInString:NMUBERS] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
BOOL basicTest = [string isEqualToString:filtered];
if(basicTest) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入汉字或英文" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
//若输入的不是汉字或者字母删除输入的内容
textField.text = nil;//return NO 时不能删除,
}
return YES;
2、#define NUMBERS @"0123456789."//只允许输入数字或者点号
不同的限制改变不同的表达式即可