似乎无法弄清楚如何检查字符串,以便不允许连续使用相同的两个字符。
我不希望任何人能够使用“00”提交数据。
答案 0 :(得分:1)
仅仅是:
(\d)\1+
\d
匹配任何数字,\1+
匹配第一位匹配的内容,当它出现多次时。
虽然与您的评论有关,但检查起来要容易得多:
if ([expiryDate rangeOfString:@"00"].location != NSNotFound)
{
//Invalid date
}
甚至可能更有效:
NSArray *components = [expiryDate componentsSeparatedByString:@"/"];
int month = [components[0] intValue];
int year = [components[1] intValue];
NSAssert(month > 0 && month <= 12, @"Invalid Month");
NSAssert(year >= 13 /*current year*/ /* (optionally) && year < 20 (or some other future year)*/, @"Invalid year");