【发布时间】:2016-02-02 00:36:33
【问题描述】:
在我的 iOS 项目中,我想验证密码,我应该接受严格的字母数字密码,即密码必须同时包含字母和数字,我通过以下方法完成了此操作,但它以数字为可选的,看起来很简单,但它占用了我的时间,请帮助我
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[a-z0-9]*"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSArray *matches = [regex matchesInString:input
options:0
range:NSMakeRange(0, [input length])];
if([matches count] > 0)
{
// Valid input
return true;
}
else
{
return false;
}
【问题讨论】:
标签: ios objective-c iphone regex nsregularexpression