0
我想使用正则表达式在iOS中验证用户名。为此,我使用NSPredicate,但它引发了运行时错误。ios:使用NSPredicate检查正则表达式 - 无法解析格式字符串
下面是我在我的ViewController:
@property (nonatomic, strong) NSString *userNamePattern;
和:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
_userNamePattern = @"[a-zA-Z0-9_-]{3,20}";
然后在动作上的一个按钮,当点击:
NSPredicate *userNameTest = [NSPredicate predicateWithFormat:self.userNamePattern];
那个底线是抛出此错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "[a-zA-Z0-9_-]{3,20}"'
为什么不是这样?
嗯,就是这样。谢谢! – user1513171 2014-09-18 16:43:16